Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed imports/exports that are illegal identifiers in the es output (#…
…4939) * Fixed exports that are illegal identifiers in the es output * Unify shared~ regex into `isValidIdentifier` util * fixed more cases --------- Co-authored-by: Lukas Taegert-Atkinson <lukastaegert@users.noreply.github.com>
- Loading branch information
1 parent
f1538ce
commit 3bbf6ae
Showing
12 changed files
with
243 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const validIdentifier = /^(?!\d)[\w$]+$/; | ||
|
||
export function isValidIdentifier(name: string): boolean { | ||
return validIdentifier.test(name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
test/form/samples/illegal-identifiers-in-imports-exports/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = { | ||
description: 'correctly handles illegal identifiers in exports/imports', | ||
options: { | ||
input: ['main'], | ||
output: { | ||
name: 'illegalIdentifiers' | ||
}, | ||
external: ['external'] | ||
} | ||
}; |
41 changes: 41 additions & 0 deletions
41
test/form/samples/illegal-identifiers-in-imports-exports/_expected/amd.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
define(['exports', 'external'], (function (exports, external) { 'use strict'; | ||
|
||
function _interopNamespaceDefault(e) { | ||
var n = Object.create(null); | ||
if (e) { | ||
Object.keys(e).forEach(function (k) { | ||
if (k !== 'default') { | ||
var d = Object.getOwnPropertyDescriptor(e, k); | ||
Object.defineProperty(n, k, d.get ? d : { | ||
enumerable: true, | ||
get: function () { return e[k]; } | ||
}); | ||
} | ||
}); | ||
} | ||
n.default = e; | ||
return Object.freeze(n); | ||
} | ||
|
||
var external__namespace = /*#__PURE__*/_interopNamespaceDefault(external); | ||
|
||
console.log(external[":"], external["🤷♂️"]); // retain those local bindings | ||
|
||
const legal = 10; | ||
|
||
Object.defineProperty(exports, '-', { | ||
enumerable: true, | ||
get: function () { return external.bar; } | ||
}); | ||
Object.defineProperty(exports, '/', { | ||
enumerable: true, | ||
get: function () { return external["/"]; } | ||
}); | ||
exports["🍅"] = external__namespace; | ||
Object.defineProperty(exports, '😭', { | ||
enumerable: true, | ||
get: function () { return external["😂"]; } | ||
}); | ||
exports["🔥illegal"] = legal; | ||
|
||
})); |
41 changes: 41 additions & 0 deletions
41
test/form/samples/illegal-identifiers-in-imports-exports/_expected/cjs.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
|
||
var external = require('external'); | ||
|
||
function _interopNamespaceDefault(e) { | ||
var n = Object.create(null); | ||
if (e) { | ||
Object.keys(e).forEach(function (k) { | ||
if (k !== 'default') { | ||
var d = Object.getOwnPropertyDescriptor(e, k); | ||
Object.defineProperty(n, k, d.get ? d : { | ||
enumerable: true, | ||
get: function () { return e[k]; } | ||
}); | ||
} | ||
}); | ||
} | ||
n.default = e; | ||
return Object.freeze(n); | ||
} | ||
|
||
var external__namespace = /*#__PURE__*/_interopNamespaceDefault(external); | ||
|
||
console.log(external[":"], external["🤷♂️"]); // retain those local bindings | ||
|
||
const legal = 10; | ||
|
||
Object.defineProperty(exports, '-', { | ||
enumerable: true, | ||
get: function () { return external.bar; } | ||
}); | ||
Object.defineProperty(exports, '/', { | ||
enumerable: true, | ||
get: function () { return external["/"]; } | ||
}); | ||
exports["🍅"] = external__namespace; | ||
Object.defineProperty(exports, '😭', { | ||
enumerable: true, | ||
get: function () { return external["😂"]; } | ||
}); | ||
exports["🔥illegal"] = legal; |
10 changes: 10 additions & 0 deletions
10
test/form/samples/illegal-identifiers-in-imports-exports/_expected/es.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ":" as _safe, "🤷♂️" as _safe$1 } from 'external'; | ||
import * as external from 'external'; | ||
export { external as "🍅" }; | ||
export { bar as "-", "/", "😂" as "😭" } from 'external'; | ||
|
||
console.log(_safe, _safe$1); // retain those local bindings | ||
|
||
const legal = 10; | ||
|
||
export { legal as "🔥illegal" }; |
44 changes: 44 additions & 0 deletions
44
test/form/samples/illegal-identifiers-in-imports-exports/_expected/iife.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
var illegalIdentifiers = (function (exports, external) { | ||
'use strict'; | ||
|
||
function _interopNamespaceDefault(e) { | ||
var n = Object.create(null); | ||
if (e) { | ||
Object.keys(e).forEach(function (k) { | ||
if (k !== 'default') { | ||
var d = Object.getOwnPropertyDescriptor(e, k); | ||
Object.defineProperty(n, k, d.get ? d : { | ||
enumerable: true, | ||
get: function () { return e[k]; } | ||
}); | ||
} | ||
}); | ||
} | ||
n.default = e; | ||
return Object.freeze(n); | ||
} | ||
|
||
var external__namespace = /*#__PURE__*/_interopNamespaceDefault(external); | ||
|
||
console.log(external[":"], external["🤷♂️"]); // retain those local bindings | ||
|
||
const legal = 10; | ||
|
||
Object.defineProperty(exports, '-', { | ||
enumerable: true, | ||
get: function () { return external.bar; } | ||
}); | ||
Object.defineProperty(exports, '/', { | ||
enumerable: true, | ||
get: function () { return external["/"]; } | ||
}); | ||
exports["🍅"] = external__namespace; | ||
Object.defineProperty(exports, '😭', { | ||
enumerable: true, | ||
get: function () { return external["😂"]; } | ||
}); | ||
exports["🔥illegal"] = legal; | ||
|
||
return exports; | ||
|
||
})({}, external); |
18 changes: 18 additions & 0 deletions
18
test/form/samples/illegal-identifiers-in-imports-exports/_expected/system.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
System.register('illegalIdentifiers', ['external'], (function (exports) { | ||
'use strict'; | ||
var _safe, _safe$1; | ||
return { | ||
setters: [function (module) { | ||
_safe = module[":"]; | ||
_safe$1 = module["🤷♂️"]; | ||
exports({ '-': module.bar, '/': module["/"], '🍅': module, '😭': module["😂"] }); | ||
}], | ||
execute: (function () { | ||
|
||
console.log(_safe, _safe$1); // retain those local bindings | ||
|
||
const legal = exports('🔥illegal', 10); | ||
|
||
}) | ||
}; | ||
})); |
45 changes: 45 additions & 0 deletions
45
test/form/samples/illegal-identifiers-in-imports-exports/_expected/umd.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('external')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'external'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.illegalIdentifiers = {}, global.external)); | ||
})(this, (function (exports, external) { 'use strict'; | ||
|
||
function _interopNamespaceDefault(e) { | ||
var n = Object.create(null); | ||
if (e) { | ||
Object.keys(e).forEach(function (k) { | ||
if (k !== 'default') { | ||
var d = Object.getOwnPropertyDescriptor(e, k); | ||
Object.defineProperty(n, k, d.get ? d : { | ||
enumerable: true, | ||
get: function () { return e[k]; } | ||
}); | ||
} | ||
}); | ||
} | ||
n.default = e; | ||
return Object.freeze(n); | ||
} | ||
|
||
var external__namespace = /*#__PURE__*/_interopNamespaceDefault(external); | ||
|
||
console.log(external[":"], external["🤷♂️"]); // retain those local bindings | ||
|
||
const legal = 10; | ||
|
||
Object.defineProperty(exports, '-', { | ||
enumerable: true, | ||
get: function () { return external.bar; } | ||
}); | ||
Object.defineProperty(exports, '/', { | ||
enumerable: true, | ||
get: function () { return external["/"]; } | ||
}); | ||
exports["🍅"] = external__namespace; | ||
Object.defineProperty(exports, '😭', { | ||
enumerable: true, | ||
get: function () { return external["😂"]; } | ||
}); | ||
exports["🔥illegal"] = legal; | ||
|
||
})); |
11 changes: 11 additions & 0 deletions
11
test/form/samples/illegal-identifiers-in-imports-exports/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { ':' as baz, '🤷♂️' as bazinga } from 'external'; | ||
console.log(baz, bazinga); // retain those local bindings | ||
|
||
const legal = 10; | ||
|
||
export { legal as '🔥illegal' }; | ||
|
||
export { bar as '-', '/', '😂' as '😭' } from 'external'; | ||
|
||
import * as lib from 'external'; | ||
export { lib as '🍅' } |