Skip to content

Commit

Permalink
refactor(module-source): More compact boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Sep 5, 2024
1 parent 1c71b66 commit e04e72d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
17 changes: 5 additions & 12 deletions packages/module-source/src/transform-analyze.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const makeCreateStaticRecord = transformSource =>
.map(
src =>
`[${js(src)}, [${Object.entries(isrc[src])
.map(([exp, upds]) => `[${js(exp)}, [${upds.join(',')}]]`)
.map(([exp, upds]) => `[${js(exp)},[${upds.join(',')}]]`)
.join(',')}]]`,
)
.join(',')}]);`;
Expand All @@ -80,9 +80,7 @@ const makeCreateStaticRecord = transformSource =>
let src = '';
if (cvname) {
// It's a function assigned to, so set its name property.
src = `Object.defineProperty(${cvname}, 'name', {value: ${js(
vname,
)}});`;
src = `Object.defineProperty(${cvname},'name',{value:${js(vname)}});`;
}
const hDeclId = isOnce ? h.HIDDEN_ONCE : h.HIDDEN_LIVE;
src += `${hDeclId}.${vname}(${cvname || ''});`;
Expand All @@ -99,14 +97,9 @@ const makeCreateStaticRecord = transformSource =>
// well.
// Relies on the evaluator to ensure these functions are strict.
let functorSource = `\
({ \
imports: ${h.HIDDEN_IMPORTS}, \
liveVar: ${h.HIDDEN_LIVE}, \
onceVar: ${h.HIDDEN_ONCE}, \
importMeta: ${h.HIDDEN_META}, \
}) => (function () { 'use strict'; \
${preamble} \
${scriptSource}
({imports:${h.HIDDEN_IMPORTS},liveVar:${h.HIDDEN_LIVE},onceVar:${h.HIDDEN_ONCE},importMeta:${h.HIDDEN_META}})=>(function(){'use strict';\
${preamble}\
${scriptSource}
})()
`;

Expand Down
2 changes: 1 addition & 1 deletion packages/module-source/test/fixtures/format-preserved.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
({ imports: $h͏_imports, liveVar: $h͏_live, onceVar: $h͏_once, importMeta: $h͏____meta, }) => (function () { 'use strict'; $h͏_imports([]);Object.defineProperty(createBinop, 'name', {value: "createBinop"});$h͏_once.createBinop(createBinop); // deliberately offset
({imports:$h͏_imports,liveVar:$h͏_live,onceVar:$h͏_once,importMeta:$h͏____meta})=>(function(){'use strict';$h͏_imports([]);Object.defineProperty(createBinop,'name',{value:"createBinop"});$h͏_once.createBinop(createBinop);// deliberately offset
function TokenType() {}
const beforeExpr = 0;

Expand Down

0 comments on commit e04e72d

Please sign in to comment.