Skip to content

Commit e6136eb

Browse files
authored
Merge branch 'master' into async-to-promises-helpers
2 parents caf3dca + 1c90d6b commit e6136eb

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed

src/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ const toReplacementExpression = (value, name) => {
3333
return [JSON.stringify(matches[2]), name];
3434
}
3535

36+
// --define @assign=Object.assign replaces expressions with expressions:
37+
if (name[0] === '@') {
38+
return [value, name.substring(1)];
39+
}
40+
3641
// --define A=1,B=true produces int/boolean literal:
3742
if (/^(true|false|\d+)$/i.test(value)) {
3843
return [value, name];

test/__snapshots__/index.test.js.snap

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,6 +1469,30 @@ exports[`fixtures build define with microbundle 5`] = `
14691469
"
14701470
`;
14711471
1472+
exports[`fixtures build define-expression with microbundle 1`] = `
1473+
"Used script: microbundle -f esm --no-sourcemap --define @Object.freeze=Object
1474+
1475+
Directory tree:
1476+
1477+
define-expression
1478+
dist
1479+
define-expression.js
1480+
index.js
1481+
package.json
1482+
1483+
1484+
Build \\"defineExpression\\" to dist:
1485+
56 B: define-expression.js.gz
1486+
40 B: define-expression.js.br"
1487+
`;
1488+
1489+
exports[`fixtures build define-expression with microbundle 2`] = `1`;
1490+
1491+
exports[`fixtures build define-expression with microbundle 3`] = `
1492+
"console.log(Object({a:\\"b\\",c:\\"d\\"}));
1493+
"
1494+
`;
1495+
14721496
exports[`fixtures build esnext-ts with microbundle 1`] = `
14731497
"Used script: microbundle --raw
14741498
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log(Object.freeze({ a: 'b', c: 'd' }));
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "define-expression",
3+
"scripts": {
4+
"build": "microbundle -f esm --no-sourcemap --define @Object.freeze=Object"
5+
}
6+
}

test/index.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const FIXTURES_DIR = `${__dirname}/fixtures`;
88
const DEFAULT_SCRIPT = 'microbundle';
99
const TEST_TIMEOUT = 11000;
1010

11+
const sleep = ms => new Promise(r => setTimeout(r, ms));
12+
1113
const join = (arr, delimiter = '') => arr.join(delimiter);
1214

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

44+
await sleep(1);
45+
4246
const output = await buildDirectory(fixtureDir);
4347

48+
await sleep(1);
49+
4450
const printedDir = printTree([dirTree(fixturePath)]);
4551

4652
expect(

0 commit comments

Comments
 (0)