Skip to content

Instantly share code, notes, and snippets.

@radex
Created August 26, 2020 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radex/cc0e443f019bc0f94a76fcbd9200b48e to your computer and use it in GitHub Desktop.
Save radex/cc0e443f019bc0f94a76fcbd9200b48e to your computer and use it in GitHub Desktop.
// ModuleGraph/worker/JSFileWrapping.js
function normalizeFileName(name) {
return '_' + name.replace(/[^a-zA-Z0-9]/g, '_')
}
function wrapModule(
// ...
, fileName) {
// ...
const factory = functionFromProgram(fileAst.program, params, normalizeFileName(fileName))
// ...
}
function functionFromProgram(program, parameters, name) {
return t.functionExpression(
t.identifier(name || ''),
parameters.map(makeIdentifier),
t.blockStatement(program.body, program.directives),
)
}
// JSTransformer/worker.js
var _JsFileWrapping$wrapM = JsFileWrapping.wrapModule(
// ...
filename
);
@radex
Copy link
Author

radex commented Sep 7, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment