-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: excise @babel/core except from ui-components
- Loading branch information
1 parent
f533f76
commit af564f1
Showing
9 changed files
with
70 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import * as babelParser from '@agoric/babel-parser'; | ||
import traverse, { NodePath } from '@babel/traverse'; | ||
import generator from '@babel/generator'; | ||
import * as types from '@babel/types'; | ||
|
||
// Create a file structure to wire into @babel/traverse. | ||
export function makePureFile({ code, ast }) { | ||
const file = { | ||
ast, | ||
opts: {}, | ||
code, | ||
}; | ||
file.hub = { | ||
file, | ||
getCode: () => file.code, | ||
getScope: () => file.scope, | ||
addHelper() { | ||
throw Error(`Helpers are not supported by the fake file hub.`); | ||
}, | ||
buildError(_node, msg, Error = TypeError) { | ||
return new Error(msg); | ||
}, | ||
}; | ||
file.path = NodePath.get({ | ||
hub: file.hub, | ||
parentPath: null, | ||
parent: file.ast, | ||
container: file.ast, | ||
key: 'program', | ||
}).setContext(); | ||
file.scope = file.path.scope; | ||
return file; | ||
} | ||
|
||
/** | ||
* Create a working subset of babelCore that doesn't touch the filesystem. | ||
*/ | ||
export function makePureBabelCore() { | ||
return { | ||
parseSync(source, { parserOpts = undefined } = {}) { | ||
return babelParser.parse(source, parserOpts); | ||
}, | ||
transformFromAstSync(ast, code = undefined, transformOptions = undefined) { | ||
const { generatorOpts, plugins } = transformOptions || {}; | ||
|
||
const pluginArgs = [{ types }]; | ||
const visitors = plugins | ||
.map(p => p(...pluginArgs).visitor) | ||
.filter(v => v); | ||
if (!visitors.length) { | ||
// We fail here because a null transform is unnecessary. | ||
throw Error(`No visitors found in plugins`); | ||
} | ||
const visitor = traverse.visitors.merge(visitors); | ||
const file = makePureFile({ ast, code }); | ||
traverse(file.ast, visitor); | ||
return generator(ast, generatorOpts, code); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters