requirejs-esm 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/esm2requirejs.js +10 -6
- package/dist/api.js +5671 -5562
- package/dist/api.js.map +1 -1
- package/dist/plugin.js +5596 -5562
- package/dist/plugin.js.map +1 -1
- package/package.json +29 -33
- package/src/api.d.ts +38 -0
- package/src/api.js +3 -0
- package/src/fetch-text.js +35 -0
- package/src/plugin.js +147 -0
- package/src/resolve-path.js +80 -0
- package/src/skip-module.js +18 -0
- package/src/transform.js +46 -0
- package/src/transformer/amd.js +101 -0
- package/src/transformer/converters.js +102 -0
- package/src/transformer/esm.js +367 -0
- package/src/transformer/factories.js +55 -0
- package/src/transformer/generate-id.js +96 -0
- package/src/transformer/identifier.js +75 -0
- package/src/transformer/index.js +22 -0
- package/src/transformer/keywords.js +74 -0
- package/src/transformer/validators.js +29 -0
- package/src/write-text.js +16 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const reservedWords = {
|
|
2
|
+
keyword: [
|
|
3
|
+
'break',
|
|
4
|
+
'case',
|
|
5
|
+
'catch',
|
|
6
|
+
'continue',
|
|
7
|
+
'debugger',
|
|
8
|
+
'default',
|
|
9
|
+
'do',
|
|
10
|
+
'else',
|
|
11
|
+
'finally',
|
|
12
|
+
'for',
|
|
13
|
+
'function',
|
|
14
|
+
'if',
|
|
15
|
+
'return',
|
|
16
|
+
'switch',
|
|
17
|
+
'throw',
|
|
18
|
+
'try',
|
|
19
|
+
'var',
|
|
20
|
+
'const',
|
|
21
|
+
'while',
|
|
22
|
+
'with',
|
|
23
|
+
'new',
|
|
24
|
+
'this',
|
|
25
|
+
'super',
|
|
26
|
+
'class',
|
|
27
|
+
'extends',
|
|
28
|
+
'export',
|
|
29
|
+
'import',
|
|
30
|
+
'null',
|
|
31
|
+
'true',
|
|
32
|
+
'false',
|
|
33
|
+
'in',
|
|
34
|
+
'instanceof',
|
|
35
|
+
'typeof',
|
|
36
|
+
'void',
|
|
37
|
+
'delete'
|
|
38
|
+
],
|
|
39
|
+
strict: [
|
|
40
|
+
'implements',
|
|
41
|
+
'interface',
|
|
42
|
+
'let',
|
|
43
|
+
'package',
|
|
44
|
+
'private',
|
|
45
|
+
'protected',
|
|
46
|
+
'public',
|
|
47
|
+
'static',
|
|
48
|
+
'yield'
|
|
49
|
+
],
|
|
50
|
+
strictBind: ['eval', 'arguments']
|
|
51
|
+
}
|
|
52
|
+
const keywords = new Set(reservedWords.keyword)
|
|
53
|
+
const reservedWordsStrictSet = new Set(reservedWords.strict)
|
|
54
|
+
const reservedWordsStrictBindSet = new Set(reservedWords.strictBind)
|
|
55
|
+
|
|
56
|
+
export function isReservedWord(word, inModule) {
|
|
57
|
+
return inModule && word === 'await' || word === 'enum'
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function isStrictReservedWord(word, inModule) {
|
|
61
|
+
return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function isStrictBindOnlyReservedWord(word) {
|
|
65
|
+
return reservedWordsStrictBindSet.has(word)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function isStrictBindReservedWord(word, inModule) {
|
|
69
|
+
return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function isKeyword(word) {
|
|
73
|
+
return keywords.has(word)
|
|
74
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { isIdentifierName } from './identifier'
|
|
2
|
+
import { isKeyword, isStrictReservedWord } from './keywords'
|
|
3
|
+
|
|
4
|
+
export function isValidIdentifier(name, reserved = true) {
|
|
5
|
+
if (typeof name !== 'string') return false
|
|
6
|
+
if (reserved && (isKeyword(name) || isStrictReservedWord(name, true))) return false
|
|
7
|
+
return isIdentifierName(name)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Checks an anonymous import.
|
|
11
|
+
export function isAnonymousImport(importNode) {
|
|
12
|
+
// import "some"
|
|
13
|
+
return importNode.specifiers.length === 0
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Checks a default import.
|
|
17
|
+
export function isImportDefault(importNode) {
|
|
18
|
+
// import some from "some"
|
|
19
|
+
return importNode.specifiers.length === 1 &&
|
|
20
|
+
importNode.specifiers[0].type === 'ImportDefaultSpecifier'
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Checks importing all named exports to an object.
|
|
24
|
+
export function isImportAllAs(importNode) {
|
|
25
|
+
// import * as some from "some"
|
|
26
|
+
return importNode.specifiers.length === 1 &&
|
|
27
|
+
importNode.specifiers[0].type !== 'ImportDefaultSpecifier' &&
|
|
28
|
+
!importNode.specifiers[0].imported
|
|
29
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/* global require */
|
|
2
|
+
|
|
3
|
+
let writeText
|
|
4
|
+
|
|
5
|
+
// Initialise the writeText variable with a function to write to a file.
|
|
6
|
+
/* istanbul ignore if */
|
|
7
|
+
if (!(typeof window !== 'undefined' && window.navigator && window.document)) {
|
|
8
|
+
const { writeFileSync, mkdirSync } = require.nodeRequire ? require.nodeRequire('fs') : require('fs')
|
|
9
|
+
const { dirname } = require.nodeRequire ? require.nodeRequire('path') : require('path')
|
|
10
|
+
writeText = (path, content) => {
|
|
11
|
+
mkdirSync(dirname(path), { recursive: true })
|
|
12
|
+
writeFileSync(path, content)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default writeText
|