Skip to content

Commit

Permalink
Merge branch 'master' into async-to-promises-helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
developit committed May 1, 2020
2 parents caf3dca + 1c90d6b commit e6136eb
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ const toReplacementExpression = (value, name) => {
return [JSON.stringify(matches[2]), name];
}

// --define @assign=Object.assign replaces expressions with expressions:
if (name[0] === '@') {
return [value, name.substring(1)];
}

// --define A=1,B=true produces int/boolean literal:
if (/^(true|false|\d+)$/i.test(value)) {
return [value, name];
Expand Down
24 changes: 24 additions & 0 deletions test/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,30 @@ exports[`fixtures build define with microbundle 5`] = `
"
`;
exports[`fixtures build define-expression with microbundle 1`] = `
"Used script: microbundle -f esm --no-sourcemap --define @Object.freeze=Object
Directory tree:
define-expression
dist
define-expression.js
index.js
package.json
Build \\"defineExpression\\" to dist:
56 B: define-expression.js.gz
40 B: define-expression.js.br"
`;
exports[`fixtures build define-expression with microbundle 2`] = `1`;
exports[`fixtures build define-expression with microbundle 3`] = `
"console.log(Object({a:\\"b\\",c:\\"d\\"}));
"
`;
exports[`fixtures build esnext-ts with microbundle 1`] = `
"Used script: microbundle --raw
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/define-expression/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log(Object.freeze({ a: 'b', c: 'd' }));
6 changes: 6 additions & 0 deletions test/fixtures/define-expression/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "define-expression",
"scripts": {
"build": "microbundle -f esm --no-sourcemap --define @Object.freeze=Object"
}
}
6 changes: 6 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const FIXTURES_DIR = `${__dirname}/fixtures`;
const DEFAULT_SCRIPT = 'microbundle';
const TEST_TIMEOUT = 11000;

const sleep = ms => new Promise(r => setTimeout(r, ms));

const join = (arr, delimiter = '') => arr.join(delimiter);

const printTree = (nodes, indentLevel = 0) => {
Expand Down Expand Up @@ -39,8 +41,12 @@ describe('fixtures', () => {
fixturePath = resolve(fixturePath, fixtureDir.replace('-with-cwd', ''));
}

await sleep(1);

const output = await buildDirectory(fixtureDir);

await sleep(1);

const printedDir = printTree([dirTree(fixturePath)]);

expect(
Expand Down

0 comments on commit e6136eb

Please sign in to comment.