Skip to content

Commit

Permalink
fix(module-source): Sub non-conforming ZWJ prefixes with CGJ
Browse files Browse the repository at this point in the history
  • Loading branch information
SMotaal committed Aug 28, 2024
1 parent 67141a1 commit eff44d1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 41 deletions.
72 changes: 36 additions & 36 deletions packages/module-source/TESTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Pairs of module source vs functor source. The output was generated.
```

```js
(({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { $h‍_imports(new Map([]), []); const { default: $c_default } = { default: bb };$h‍_once.default($c‍_default);
(({ imports: $h͏_imports, liveVar: $h͏_live, onceVar: $h͏_once, }) => { $_imports(new Map([]), []); const { default: $c\u034f_default } = { default: bb };$_once.default($c\u034f_default);
})
```

Expand All @@ -24,7 +24,7 @@ Pairs of module source vs functor source. The output was generated.
```

```js
(({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { $h‍_imports(new Map([]), []); const { default: $c_default } = { default: class {valueOf() {return 45;}} };$h‍_once.default($c‍_default);
(({ imports: $h͏_imports, liveVar: $h͏_live, onceVar: $h͏_once, }) => { $_imports(new Map([]), []); const { default: $c\u034f_default } = { default: class {valueOf() {return 45;}} };$_once.default($c\u034f_default);
})
```

Expand All @@ -36,8 +36,8 @@ export default 123
```

```js
(({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { $h‍_imports(new Map([]), []); //#! /usr/bin/env node
const { default: $c_default } = { default: 123 };$h‍_once.default($c‍_default);
(({ imports: $h͏_imports, liveVar: $h͏_live, onceVar: $h͏_once, }) => { $_imports(new Map([]), []); //#! /usr/bin/env node
const { default: $c\u034f_default } = { default: 123 };$_once.default($c\u034f_default);
})
```

Expand All @@ -48,7 +48,7 @@ const { default: $c‍_default } = { default: 123 };$h‍_once.default($c‍_def
```

```js
(({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { $h‍_imports(new Map([]), []); const { default: $c_default } = { default: arguments };$h‍_once.default($c‍_default);
(({ imports: $h͏_imports, liveVar: $h͏_live, onceVar: $h͏_once, }) => { $_imports(new Map([]), []); const { default: $c\u034f_default } = { default: arguments };$_once.default($c\u034f_default);
})
```

Expand All @@ -59,7 +59,7 @@ const { default: $c‍_default } = { default: 123 };$h‍_once.default($c‍_def
```

```js
(({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { $h‍_imports(new Map([]), []); const { default: $c_default } = { default: this };$h‍_once.default($c‍_default);
(({ imports: $h͏_imports, liveVar: $h͏_live, onceVar: $h͏_once, }) => { $_imports(new Map([]), []); const { default: $c\u034f_default } = { default: this };$_once.default($c\u034f_default);
})
```

Expand All @@ -77,11 +77,11 @@ export const ghi = 789;
```

```js
(({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { $h‍_imports(new Map([]), []); let abc = 123;$h‍_once.abc(abc);
let $c‍_def = 456;$h‍_live.def($c‍_def);
let def2 = def;$h‍_once.def2(def2);
(({ imports: $h͏_imports, liveVar: $h͏_live, onceVar: $h͏_once, }) => { $_imports(new Map([]), []); let abc = 123;$_once.abc(abc);
let $c\u034f_def = 456;$_live.def($c\u034f_def);
let def2 = def;$_once.def2(def2);
def++;
const ghi = 789;$h‍_once.ghi(ghi);
const ghi = 789;$_once.ghi(ghi);
})
```

Expand All @@ -94,8 +94,8 @@ export const { def, nest: [, ghi, ...nestrest], ...rest } = { def: 456, nest: [
```

```js
(({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { $h‍_imports(new Map([]), []); const abc = 123;$h‍_once.abc(abc);
const { def, nest: [, ghi, ...nestrest], ...rest } = { def: 456, nest: ['skip', 789, 'a', 'b'], other: 999, and: 998 };$h‍_once.def(def);$h‍_once.ghi(ghi);$h‍_once.nestrest(nestrest);$h‍_once.rest(rest);
(({ imports: $h͏_imports, liveVar: $h͏_live, onceVar: $h͏_once, }) => { $_imports(new Map([]), []); const abc = 123;$_once.abc(abc);
const { def, nest: [, ghi, ...nestrest], ...rest } = { def: 456, nest: ['skip', 789, 'a', 'b'], other: 999, and: 998 };$_once.def(def);$_once.ghi(ghi);$_once.nestrest(nestrest);$_once.rest(rest);
})
```

Expand All @@ -107,8 +107,8 @@ export const abc = 123;
```

```js
(({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { $h‍_imports(new Map([]), []); const abc2 = abc;
const abc = 123;$h‍_once.abc(abc);
(({ imports: $h͏_imports, liveVar: $h͏_live, onceVar: $h͏_once, }) => { $_imports(new Map([]), []); const abc2 = abc;
const abc = 123;$_once.abc(abc);
})
```

Expand All @@ -120,8 +120,8 @@ export let abc = 123;
```

```js
(({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { $h‍_imports(new Map([]), []); const abc2 = abc;
let abc = 123;$h‍_once.abc(abc);
(({ imports: $h͏_imports, liveVar: $h͏_live, onceVar: $h͏_once, }) => { $_imports(new Map([]), []); const abc2 = abc;
let abc = 123;$_once.abc(abc);
})
```

Expand All @@ -134,9 +134,9 @@ export const abc3 = abc;
```

```js
(({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { $h‍_imports(new Map([]), []);$h‍_live.abc(); const abc2 = abc;$h‍_once.abc2(abc2);
var $c‍_abc = 123;abc = $c‍_abc;
const abc3 = abc;$h‍_once.abc3(abc3);
(({ imports: $h͏_imports, liveVar: $h͏_live, onceVar: $h͏_once, }) => { $_imports(new Map([]), []);$_live.abc(); const abc2 = abc;$_once.abc2(abc2);
var $c\u034f_abc = 123;abc = $c\u034f_abc;
const abc3 = abc;$_once.abc3(abc3);
})
```

Expand All @@ -151,11 +151,11 @@ export const fn3 = fn;
```

```js
(({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { $h‍_imports(new Map([]), []);Object.defineProperty($c‍_fn, 'name', {value: "fn"});$h‍_live.fn($c‍_fn); const fn2 = fn;$h‍_once.fn2(fn2);
function $c_fn() {
(({ imports: $h͏_imports, liveVar: $h͏_live, onceVar: $h͏_once, }) => { $_imports(new Map([]), []);Object.defineProperty($c\u034f_fn, 'name', {value: "fn"});$_live.fn($c\u034f_fn); const fn2 = fn;$_once.fn2(fn2);
function $c\u034f_fn() {
return 'foo';
}
const fn3 = fn;$h‍_once.fn3(fn3);
const fn3 = fn;$_once.fn3(fn3);
})
```

Expand All @@ -167,8 +167,8 @@ export class C {} if (C) { count += 1; }
```

```js
(({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { $h‍_imports(new Map([]), []); let $c‍_count = 0;$h‍_live.count($c‍_count);{
class C {}$h‍_live.C(C);}if (C) {count += 1;}
(({ imports: $h͏_imports, liveVar: $h͏_live, onceVar: $h͏_once, }) => { $_imports(new Map([]), []); let $c\u034f_count = 0;$_live.count($c\u034f_count);{
class C {}$_live.C(C);}if (C) {count += 1;}
})
```

Expand All @@ -179,7 +179,7 @@ export class C {} if (C) { count += 1; }
```

```js
(({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { $h‍_imports(new Map([]), []); const { default: $c_default } = { default: class C {} };$h‍_once.default($c‍_default);
(({ imports: $h͏_imports, liveVar: $h͏_live, onceVar: $h͏_once, }) => { $_imports(new Map([]), []); const { default: $c\u034f_default } = { default: class C {} };$_once.default($c\u034f_default);
})
```

Expand All @@ -190,7 +190,7 @@ export class C {} if (C) { count += 1; }
```

```js
(({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { $h‍_imports(new Map([]), []); const { default: $c_default } = { default: class {} };$h‍_once.default($c‍_default);
(({ imports: $h͏_imports, liveVar: $h͏_live, onceVar: $h͏_once, }) => { $_imports(new Map([]), []); const { default: $c\u034f_default } = { default: class {} };$_once.default($c\u034f_default);
})
```

Expand All @@ -201,7 +201,7 @@ export class C {} if (C) { count += 1; }
```

```js
(({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { $h‍_imports(new Map([]), []); const { default: $c_default } = { default: class {} };$h‍_once.default($c‍_default);
(({ imports: $h͏_imports, liveVar: $h͏_live, onceVar: $h͏_once, }) => { $_imports(new Map([]), []); const { default: $c\u034f_default } = { default: class {} };$_once.default($c\u034f_default);
})
```

Expand All @@ -213,8 +213,8 @@ export function F(arg) { return arg; }
```

```js
(({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { $h‍_imports(new Map([]), []);Object.defineProperty($c_F, 'name', {value: "F"});$h‍_live.F($c_F); F(123);
function $c_F(arg) {return arg;}
(({ imports: $h͏_imports, liveVar: $h͏_live, onceVar: $h͏_once, }) => { $_imports(new Map([]), []);Object.defineProperty($c\u034f_F, 'name', {value: "F"});$_live.F($c\u034f_F); F(123);
function $c\u034f_F(arg) {return arg;}
})
```

Expand All @@ -225,7 +225,7 @@ function $c‍_F(arg) {return arg;}
```

```js
(({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { $h‍_imports(new Map([]), []); const { default: $c_default } = { default: async function F(arg) {return arg;} };$h‍_once.default($c‍_default);
(({ imports: $h͏_imports, liveVar: $h͏_live, onceVar: $h͏_once, }) => { $_imports(new Map([]), []); const { default: $c\u034f_default } = { default: async function F(arg) {return arg;} };$_once.default($c\u034f_default);
})
```

Expand All @@ -236,7 +236,7 @@ function $c‍_F(arg) {return arg;}
```

```js
(({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { $h‍_imports(new Map([]), []); const { default: $c_default } = { default: async function (arg) {return arg;} };$h‍_once.default($c‍_default);;
(({ imports: $h͏_imports, liveVar: $h͏_live, onceVar: $h͏_once, }) => { $_imports(new Map([]), []); const { default: $c\u034f_default } = { default: async function (arg) {return arg;} };$_once.default($c\u034f_default);;
})
```

Expand All @@ -249,7 +249,7 @@ function $c‍_F(arg) {return arg;}
```

```js
(({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { let ns;$h‍_imports(new Map([["module", new Map([["*", [$h‍_a => (ns = $h‍_a)]]])]]), []);
(({ imports: $h͏_imports, liveVar: $h͏_live, onceVar: $h͏_once, }) => { let ns;$_imports(new Map([["module", new Map([["*", [$_a => (ns = $h͏_a)]]])]]), []);
})
```

Expand All @@ -260,7 +260,7 @@ function $c‍_F(arg) {return arg;}
```

```js
(({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { let foo,bar;$h‍_imports(new Map([["module", new Map([["foo", [$h‍_a => (foo = $h‍_a)]],["bar", [$h‍_a => (bar = $h‍_a)]]])]]), []);
(({ imports: $h͏_imports, liveVar: $h͏_live, onceVar: $h͏_once, }) => { let foo,bar;$_imports(new Map([["module", new Map([["foo", [$_a => (foo = $h͏_a)]],["bar", [$_a => (bar = $h͏_a)]]])]]), []);
})
```
#### Case 3
Expand All @@ -270,7 +270,7 @@ function $c‍_F(arg) {return arg;}
```

```js
(({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { let myName;$h‍_imports(new Map([["module", new Map([["default", [$h‍_a => (myName = $h‍_a)]]])]]), []);
(({ imports: $h͏_imports, liveVar: $h͏_live, onceVar: $h͏_once, }) => { let myName;$_imports(new Map([["module", new Map([["default", [$_a => (myName = $h͏_a)]]])]]), []);
})
```

Expand All @@ -282,7 +282,7 @@ function $c‍_F(arg) {return arg;}
```

```js
(({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { let myName,other;$h‍_imports(new Map([["module", new Map([["default", [$h‍_a => (myName = $h‍_a)]],["otherName", [$h‍_a => (other = $h‍_a)]]])]]), []);
(({ imports: $h͏_imports, liveVar: $h͏_live, onceVar: $h͏_once, }) => { let myName,other;$_imports(new Map([["module", new Map([["default", [$_a => (myName = $h͏_a)]],["otherName", [$_a => (other = $h͏_a)]]])]]), []);
})
```

Expand All @@ -294,6 +294,6 @@ function $c‍_F(arg) {return arg;}
```

```js
(({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { $h‍_imports(new Map([["module", new Map([])]]), []);
(({ imports: $h͏_imports, liveVar: $h͏_live, onceVar: $h͏_once, }) => { $_imports(new Map([["module", new Map([])]]), []);
})
```
4 changes: 2 additions & 2 deletions packages/module-source/src/hidden.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const HIDDEN_PREFIX = '$h\u200d_';
export const HIDDEN_CONST_VAR_PREFIX = '$c\u200d_';
export const HIDDEN_PREFIX = '$h\u034f_';
export const HIDDEN_CONST_VAR_PREFIX = '$c\u034f_';
export const HIDDEN_A = `${HIDDEN_PREFIX}a`;
export const HIDDEN_IMPORT = `${HIDDEN_PREFIX}import`;
export const HIDDEN_IMPORT_SELF = `${HIDDEN_PREFIX}importSelf`;
Expand Down
6 changes: 3 additions & 3 deletions packages/module-source/test/module-source.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,20 +444,20 @@ export default async function (arg) { return arg; }

test('zero width joiner is reserved', t => {
t.throws(() => {
const _ = new ModuleSource(`const $h\u200d_import = 123; $h\u200d_import`);
const _ = new ModuleSource(`const $h\u034f_import = 123; $h\u034f_import`);
});
});

test('zero width joiner in constified variable is reserved', t => {
t.throws(() => {
const _ = new ModuleSource(`const $c\u200d_myVar = 123; $c\u200d_myVar`);
const _ = new ModuleSource(`const $c\u034f_myVar = 123; $c\u034f_myVar`);
});
});

test('zero width joiner is allowed in non-reserved words', t => {
const { namespace } = initialize(
t,
`const $h\u200d_import2 = 123; export default $h\u200d_import2`,
`const $h\u034f_import2 = 123; export default $h\u034f_import2`,
);
const { default: name } = namespace;
t.is(name, 123);
Expand Down

0 comments on commit eff44d1

Please sign in to comment.