vite 2.6.0-beta.0 → 2.6.0-beta.4
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.
Potentially problematic release.
This version of vite might be problematic. Click here for more details.
- package/CHANGELOG.md +66 -0
- package/LICENSE.md +161 -3011
- package/bin/vite.js +2 -1
- package/dist/node/chunks/{dep-91aa74e8.js → dep-1e0a75a8.js} +58 -32
- package/dist/node/chunks/dep-1e0a75a8.js.map +1 -0
- package/dist/node/chunks/{dep-e36486f6.js → dep-ac1b4bf9.js} +1 -1
- package/dist/node/chunks/dep-ac1b4bf9.js.map +1 -0
- package/dist/node/chunks/{dep-c7e510f9.js → dep-ba6b30a0.js} +27538 -4953
- package/dist/node/chunks/dep-ba6b30a0.js.map +1 -0
- package/dist/node/chunks/{dep-11213a75.js → dep-c4cf6e92.js} +19 -6
- package/dist/node/chunks/dep-c4cf6e92.js.map +1 -0
- package/dist/node/chunks/{dep-eb6ef720.js → dep-d574094c.js} +18 -5
- package/dist/node/chunks/dep-d574094c.js.map +1 -0
- package/dist/node/chunks/{dep-0d2f9464.js → dep-e39b05d6.js} +18 -5
- package/dist/node/chunks/dep-e39b05d6.js.map +1 -0
- package/dist/node/cli.js +60 -23992
- package/dist/node/cli.js.map +1 -1
- package/dist/node/index.d.ts +26 -8
- package/dist/node/index.js +18 -15
- package/dist/node/index.js.map +1 -1
- package/dist/node/terser.js +102 -55
- package/package.json +28 -13
- package/types/package.json +3 -0
- package/api-extractor.json +0 -54
- package/dist/node/chunks/dep-0d2f9464.js.map +0 -1
- package/dist/node/chunks/dep-11213a75.js.map +0 -1
- package/dist/node/chunks/dep-91aa74e8.js.map +0 -1
- package/dist/node/chunks/dep-c7e510f9.js.map +0 -1
- package/dist/node/chunks/dep-e36486f6.js.map +0 -1
- package/dist/node/chunks/dep-eb6ef720.js.map +0 -1
- package/dist/node/terser.js.map +0 -1
- package/rollup.config.js +0 -389
- package/scripts/patchTypes.js +0 -70
- package/src/node/__tests__/asset.spec.ts +0 -156
- package/src/node/__tests__/build.spec.ts +0 -67
- package/src/node/__tests__/config.spec.ts +0 -166
- package/src/node/__tests__/packages/name/package.json +0 -3
- package/src/node/__tests__/packages/noname/package.json +0 -1
- package/src/node/__tests__/plugins/css.spec.ts +0 -116
- package/src/node/__tests__/scan.spec.ts +0 -118
- package/src/node/__tests__/utils.spec.ts +0 -40
- package/src/node/build.ts +0 -783
- package/src/node/cli.ts +0 -239
- package/src/node/config.ts +0 -1033
- package/src/node/constants.ts +0 -87
- package/src/node/importGlob.ts +0 -173
- package/src/node/index.ts +0 -88
- package/src/node/logger.ts +0 -167
- package/src/node/optimizer/esbuildDepPlugin.ts +0 -216
- package/src/node/optimizer/index.ts +0 -410
- package/src/node/optimizer/registerMissing.ts +0 -102
- package/src/node/optimizer/scan.ts +0 -457
- package/src/node/plugin.ts +0 -138
- package/src/node/plugins/asset.ts +0 -365
- package/src/node/plugins/assetImportMetaUrl.ts +0 -99
- package/src/node/plugins/clientInjections.ts +0 -72
- package/src/node/plugins/css.ts +0 -1279
- package/src/node/plugins/dataUri.ts +0 -64
- package/src/node/plugins/define.ts +0 -107
- package/src/node/plugins/esbuild.ts +0 -280
- package/src/node/plugins/html.ts +0 -673
- package/src/node/plugins/importAnalysis.ts +0 -614
- package/src/node/plugins/importAnalysisBuild.ts +0 -334
- package/src/node/plugins/index.ts +0 -69
- package/src/node/plugins/json.ts +0 -75
- package/src/node/plugins/loadFallback.ts +0 -19
- package/src/node/plugins/manifest.ts +0 -123
- package/src/node/plugins/modulePreloadPolyfill.ts +0 -100
- package/src/node/plugins/preAlias.ts +0 -22
- package/src/node/plugins/reporter.ts +0 -244
- package/src/node/plugins/resolve.ts +0 -925
- package/src/node/plugins/terser.ts +0 -40
- package/src/node/plugins/wasm.ts +0 -72
- package/src/node/plugins/worker.ts +0 -117
- package/src/node/preview.ts +0 -82
- package/src/node/server/__tests__/fixtures/none/nested/package.json +0 -3
- package/src/node/server/__tests__/fixtures/pnpm/nested/package.json +0 -3
- package/src/node/server/__tests__/fixtures/pnpm/package.json +0 -3
- package/src/node/server/__tests__/fixtures/pnpm/pnpm-workspace.yaml +0 -0
- package/src/node/server/__tests__/fixtures/yarn/nested/package.json +0 -3
- package/src/node/server/__tests__/fixtures/yarn/package.json +0 -6
- package/src/node/server/__tests__/search-root.spec.ts +0 -31
- package/src/node/server/hmr.ts +0 -489
- package/src/node/server/http.ts +0 -198
- package/src/node/server/index.ts +0 -705
- package/src/node/server/middlewares/base.ts +0 -52
- package/src/node/server/middlewares/error.ts +0 -98
- package/src/node/server/middlewares/indexHtml.ts +0 -170
- package/src/node/server/middlewares/proxy.ts +0 -124
- package/src/node/server/middlewares/spaFallback.ts +0 -32
- package/src/node/server/middlewares/static.ts +0 -153
- package/src/node/server/middlewares/time.ts +0 -18
- package/src/node/server/middlewares/transform.ts +0 -196
- package/src/node/server/moduleGraph.ts +0 -200
- package/src/node/server/openBrowser.ts +0 -101
- package/src/node/server/pluginContainer.ts +0 -546
- package/src/node/server/searchRoot.ts +0 -70
- package/src/node/server/send.ts +0 -54
- package/src/node/server/sourcemap.ts +0 -54
- package/src/node/server/transformRequest.ts +0 -168
- package/src/node/server/ws.ts +0 -131
- package/src/node/ssr/__tests__/ssrTransform.spec.ts +0 -309
- package/src/node/ssr/ssrExternal.ts +0 -161
- package/src/node/ssr/ssrManifestPlugin.ts +0 -53
- package/src/node/ssr/ssrModuleLoader.ts +0 -214
- package/src/node/ssr/ssrStacktrace.ts +0 -75
- package/src/node/ssr/ssrTransform.ts +0 -452
- package/src/node/tsconfig.json +0 -14
- package/src/node/utils.ts +0 -565
- package/tsconfig.base.json +0 -11
|
@@ -1,452 +0,0 @@
|
|
|
1
|
-
import MagicString from 'magic-string'
|
|
2
|
-
import { SourceMap } from 'rollup'
|
|
3
|
-
import { TransformResult } from '../server/transformRequest'
|
|
4
|
-
import { parser } from '../server/pluginContainer'
|
|
5
|
-
import {
|
|
6
|
-
Identifier,
|
|
7
|
-
Node as _Node,
|
|
8
|
-
Property,
|
|
9
|
-
Function as FunctionNode
|
|
10
|
-
} from 'estree'
|
|
11
|
-
import { extract_names as extractNames } from 'periscopic'
|
|
12
|
-
import { walk as eswalk } from 'estree-walker'
|
|
13
|
-
import { combineSourcemaps } from '../utils'
|
|
14
|
-
import { RawSourceMap } from '@ampproject/remapping/dist/types/types'
|
|
15
|
-
|
|
16
|
-
type Node = _Node & {
|
|
17
|
-
start: number
|
|
18
|
-
end: number
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const ssrModuleExportsKey = `__vite_ssr_exports__`
|
|
22
|
-
export const ssrImportKey = `__vite_ssr_import__`
|
|
23
|
-
export const ssrDynamicImportKey = `__vite_ssr_dynamic_import__`
|
|
24
|
-
export const ssrExportAllKey = `__vite_ssr_exportAll__`
|
|
25
|
-
export const ssrImportMetaKey = `__vite_ssr_import_meta__`
|
|
26
|
-
|
|
27
|
-
export async function ssrTransform(
|
|
28
|
-
code: string,
|
|
29
|
-
inMap: SourceMap | null,
|
|
30
|
-
url: string
|
|
31
|
-
): Promise<TransformResult | null> {
|
|
32
|
-
const s = new MagicString(code)
|
|
33
|
-
|
|
34
|
-
const ast = parser.parse(code, {
|
|
35
|
-
sourceType: 'module',
|
|
36
|
-
ecmaVersion: 2021,
|
|
37
|
-
locations: true
|
|
38
|
-
}) as any
|
|
39
|
-
|
|
40
|
-
let uid = 0
|
|
41
|
-
const deps = new Set<string>()
|
|
42
|
-
const dynamicDeps = new Set<string>()
|
|
43
|
-
const idToImportMap = new Map<string, string>()
|
|
44
|
-
const declaredConst = new Set<string>()
|
|
45
|
-
|
|
46
|
-
function defineImport(node: Node, source: string) {
|
|
47
|
-
deps.add(source)
|
|
48
|
-
const importId = `__vite_ssr_import_${uid++}__`
|
|
49
|
-
s.appendLeft(
|
|
50
|
-
node.start,
|
|
51
|
-
`const ${importId} = await ${ssrImportKey}(${JSON.stringify(source)});\n`
|
|
52
|
-
)
|
|
53
|
-
return importId
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function defineExport(position: number, name: string, local = name) {
|
|
57
|
-
s.appendRight(
|
|
58
|
-
position,
|
|
59
|
-
`\nObject.defineProperty(${ssrModuleExportsKey}, "${name}", ` +
|
|
60
|
-
`{ enumerable: true, configurable: true, get(){ return ${local} }});`
|
|
61
|
-
)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// 1. check all import statements and record id -> importName map
|
|
65
|
-
for (const node of ast.body as Node[]) {
|
|
66
|
-
// import foo from 'foo' --> foo -> __import_foo__.default
|
|
67
|
-
// import { baz } from 'foo' --> baz -> __import_foo__.baz
|
|
68
|
-
// import * as ok from 'foo' --> ok -> __import_foo__
|
|
69
|
-
if (node.type === 'ImportDeclaration') {
|
|
70
|
-
const importId = defineImport(node, node.source.value as string)
|
|
71
|
-
for (const spec of node.specifiers) {
|
|
72
|
-
if (spec.type === 'ImportSpecifier') {
|
|
73
|
-
idToImportMap.set(
|
|
74
|
-
spec.local.name,
|
|
75
|
-
`${importId}.${spec.imported.name}`
|
|
76
|
-
)
|
|
77
|
-
} else if (spec.type === 'ImportDefaultSpecifier') {
|
|
78
|
-
idToImportMap.set(spec.local.name, `${importId}.default`)
|
|
79
|
-
} else {
|
|
80
|
-
// namespace specifier
|
|
81
|
-
idToImportMap.set(spec.local.name, importId)
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
s.remove(node.start, node.end)
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// 2. check all export statements and define exports
|
|
89
|
-
for (const node of ast.body as Node[]) {
|
|
90
|
-
// named exports
|
|
91
|
-
if (node.type === 'ExportNamedDeclaration') {
|
|
92
|
-
if (node.declaration) {
|
|
93
|
-
if (
|
|
94
|
-
node.declaration.type === 'FunctionDeclaration' ||
|
|
95
|
-
node.declaration.type === 'ClassDeclaration'
|
|
96
|
-
) {
|
|
97
|
-
// export function foo() {}
|
|
98
|
-
defineExport(node.end, node.declaration.id!.name)
|
|
99
|
-
} else {
|
|
100
|
-
// export const foo = 1, bar = 2
|
|
101
|
-
for (const declaration of node.declaration.declarations) {
|
|
102
|
-
const names = extractNames(declaration.id as any)
|
|
103
|
-
for (const name of names) {
|
|
104
|
-
defineExport(node.end, name)
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
s.remove(node.start, (node.declaration as Node).start)
|
|
109
|
-
} else {
|
|
110
|
-
s.remove(node.start, node.end)
|
|
111
|
-
if (node.source) {
|
|
112
|
-
// export { foo, bar } from './foo'
|
|
113
|
-
const importId = defineImport(node, node.source.value as string)
|
|
114
|
-
for (const spec of node.specifiers) {
|
|
115
|
-
defineExport(
|
|
116
|
-
node.end,
|
|
117
|
-
spec.exported.name,
|
|
118
|
-
`${importId}.${spec.local.name}`
|
|
119
|
-
)
|
|
120
|
-
}
|
|
121
|
-
} else {
|
|
122
|
-
// export { foo, bar }
|
|
123
|
-
for (const spec of node.specifiers) {
|
|
124
|
-
const local = spec.local.name
|
|
125
|
-
const binding = idToImportMap.get(local)
|
|
126
|
-
defineExport(node.end, spec.exported.name, binding || local)
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// default export
|
|
133
|
-
if (node.type === 'ExportDefaultDeclaration') {
|
|
134
|
-
if ('id' in node.declaration && node.declaration.id) {
|
|
135
|
-
// named hoistable/class exports
|
|
136
|
-
// export default function foo() {}
|
|
137
|
-
// export default class A {}
|
|
138
|
-
const { name } = node.declaration.id
|
|
139
|
-
s.remove(node.start, node.start + 15 /* 'export default '.length */)
|
|
140
|
-
s.append(
|
|
141
|
-
`\nObject.defineProperty(${ssrModuleExportsKey}, "default", ` +
|
|
142
|
-
`{ enumerable: true, value: ${name} });`
|
|
143
|
-
)
|
|
144
|
-
} else {
|
|
145
|
-
// anonymous default exports
|
|
146
|
-
s.overwrite(
|
|
147
|
-
node.start,
|
|
148
|
-
node.start + 14 /* 'export default'.length */,
|
|
149
|
-
`${ssrModuleExportsKey}.default =`
|
|
150
|
-
)
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// export * from './foo'
|
|
155
|
-
if (node.type === 'ExportAllDeclaration') {
|
|
156
|
-
if (node.exported) {
|
|
157
|
-
const importId = defineImport(node, node.source.value as string)
|
|
158
|
-
s.remove(node.start, node.end)
|
|
159
|
-
defineExport(node.end, node.exported.name, `${importId}`)
|
|
160
|
-
} else {
|
|
161
|
-
const importId = defineImport(node, node.source.value as string)
|
|
162
|
-
s.remove(node.start, node.end)
|
|
163
|
-
s.appendLeft(node.end, `${ssrExportAllKey}(${importId});`)
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// 3. convert references to import bindings & import.meta references
|
|
169
|
-
walk(ast, {
|
|
170
|
-
onIdentifier(id, parent, parentStack) {
|
|
171
|
-
const binding = idToImportMap.get(id.name)
|
|
172
|
-
if (!binding) {
|
|
173
|
-
return
|
|
174
|
-
}
|
|
175
|
-
if (isStaticProperty(parent) && parent.shorthand) {
|
|
176
|
-
// let binding used in a property shorthand
|
|
177
|
-
// { foo } -> { foo: __import_x__.foo }
|
|
178
|
-
// skip for destructuring patterns
|
|
179
|
-
if (
|
|
180
|
-
!(parent as any).inPattern ||
|
|
181
|
-
isInDestructuringAssignment(parent, parentStack)
|
|
182
|
-
) {
|
|
183
|
-
s.appendLeft(id.end, `: ${binding}`)
|
|
184
|
-
}
|
|
185
|
-
} else if (
|
|
186
|
-
parent.type === 'ClassDeclaration' &&
|
|
187
|
-
id === parent.superClass
|
|
188
|
-
) {
|
|
189
|
-
if (!declaredConst.has(id.name)) {
|
|
190
|
-
declaredConst.add(id.name)
|
|
191
|
-
// locate the top-most node containing the class declaration
|
|
192
|
-
const topNode = parentStack[1]
|
|
193
|
-
s.prependRight(topNode.start, `const ${id.name} = ${binding};\n`)
|
|
194
|
-
}
|
|
195
|
-
} else {
|
|
196
|
-
s.overwrite(id.start, id.end, binding)
|
|
197
|
-
}
|
|
198
|
-
},
|
|
199
|
-
onImportMeta(node) {
|
|
200
|
-
s.overwrite(node.start, node.end, ssrImportMetaKey)
|
|
201
|
-
},
|
|
202
|
-
onDynamicImport(node) {
|
|
203
|
-
s.overwrite(node.start, node.start + 6, ssrDynamicImportKey)
|
|
204
|
-
if (node.type === 'ImportExpression' && node.source.type === 'Literal') {
|
|
205
|
-
dynamicDeps.add(node.source.value as string)
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
})
|
|
209
|
-
|
|
210
|
-
let map = s.generateMap({ hires: true })
|
|
211
|
-
if (inMap && inMap.mappings && inMap.sources.length > 0) {
|
|
212
|
-
map = combineSourcemaps(url, [
|
|
213
|
-
{
|
|
214
|
-
...map,
|
|
215
|
-
sources: inMap.sources,
|
|
216
|
-
sourcesContent: inMap.sourcesContent
|
|
217
|
-
} as RawSourceMap,
|
|
218
|
-
inMap as RawSourceMap
|
|
219
|
-
]) as SourceMap
|
|
220
|
-
} else {
|
|
221
|
-
map.sources = [url]
|
|
222
|
-
map.sourcesContent = [code]
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
return {
|
|
226
|
-
code: s.toString(),
|
|
227
|
-
map,
|
|
228
|
-
deps: [...deps],
|
|
229
|
-
dynamicDeps: [...dynamicDeps]
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
interface Visitors {
|
|
234
|
-
onIdentifier: (
|
|
235
|
-
node: Identifier & {
|
|
236
|
-
start: number
|
|
237
|
-
end: number
|
|
238
|
-
},
|
|
239
|
-
parent: Node,
|
|
240
|
-
parentStack: Node[]
|
|
241
|
-
) => void
|
|
242
|
-
onImportMeta: (node: Node) => void
|
|
243
|
-
onDynamicImport: (node: Node) => void
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Same logic from \@vue/compiler-core & \@vue/compiler-sfc
|
|
248
|
-
* Except this is using acorn AST
|
|
249
|
-
*/
|
|
250
|
-
function walk(
|
|
251
|
-
root: Node,
|
|
252
|
-
{ onIdentifier, onImportMeta, onDynamicImport }: Visitors
|
|
253
|
-
) {
|
|
254
|
-
const parentStack: Node[] = []
|
|
255
|
-
const scope: Record<string, number> = Object.create(null)
|
|
256
|
-
const scopeMap = new WeakMap<_Node, Set<string>>()
|
|
257
|
-
|
|
258
|
-
const setScope = (node: FunctionNode, name: string) => {
|
|
259
|
-
let scopeIds = scopeMap.get(node)
|
|
260
|
-
if (scopeIds && scopeIds.has(name)) {
|
|
261
|
-
return
|
|
262
|
-
}
|
|
263
|
-
if (name in scope) {
|
|
264
|
-
scope[name]++
|
|
265
|
-
} else {
|
|
266
|
-
scope[name] = 1
|
|
267
|
-
}
|
|
268
|
-
if (!scopeIds) {
|
|
269
|
-
scopeIds = new Set()
|
|
270
|
-
scopeMap.set(node, scopeIds)
|
|
271
|
-
}
|
|
272
|
-
scopeIds.add(name)
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
;(eswalk as any)(root, {
|
|
276
|
-
enter(node: Node, parent: Node | null) {
|
|
277
|
-
if (node.type === 'ImportDeclaration') {
|
|
278
|
-
return this.skip()
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
parent && parentStack.push(parent)
|
|
282
|
-
|
|
283
|
-
if (node.type === 'MetaProperty' && node.meta.name === 'import') {
|
|
284
|
-
onImportMeta(node)
|
|
285
|
-
} else if (node.type === 'ImportExpression') {
|
|
286
|
-
onDynamicImport(node)
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
if (node.type === 'Identifier') {
|
|
290
|
-
if (!scope[node.name] && isRefIdentifier(node, parent!, parentStack)) {
|
|
291
|
-
onIdentifier(node, parent!, parentStack)
|
|
292
|
-
}
|
|
293
|
-
} else if (isFunction(node)) {
|
|
294
|
-
// walk function expressions and add its arguments to known identifiers
|
|
295
|
-
// so that we don't prefix them
|
|
296
|
-
node.params.forEach((p) =>
|
|
297
|
-
(eswalk as any)(p, {
|
|
298
|
-
enter(child: Node, parent: Node) {
|
|
299
|
-
if (
|
|
300
|
-
child.type === 'Identifier' &&
|
|
301
|
-
// do not record as scope variable if is a destructuring key
|
|
302
|
-
!isStaticPropertyKey(child, parent) &&
|
|
303
|
-
// do not record if this is a default value
|
|
304
|
-
// assignment of a destructuring variable
|
|
305
|
-
!(
|
|
306
|
-
parent &&
|
|
307
|
-
parent.type === 'AssignmentPattern' &&
|
|
308
|
-
parent.right === child
|
|
309
|
-
)
|
|
310
|
-
) {
|
|
311
|
-
setScope(node, child.name)
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
})
|
|
315
|
-
)
|
|
316
|
-
} else if (node.type === 'Property' && parent!.type === 'ObjectPattern') {
|
|
317
|
-
// mark property in destructuring pattern
|
|
318
|
-
;(node as any).inPattern = true
|
|
319
|
-
} else if (node.type === 'VariableDeclarator') {
|
|
320
|
-
const parentFunction = findParentFunction(parentStack)
|
|
321
|
-
if (parentFunction) {
|
|
322
|
-
if (node.id.type === 'ObjectPattern') {
|
|
323
|
-
node.id.properties.forEach((property) => {
|
|
324
|
-
if (property.type === 'RestElement') {
|
|
325
|
-
setScope(parentFunction, (property.argument as Identifier).name)
|
|
326
|
-
} else {
|
|
327
|
-
setScope(parentFunction, (property.value as Identifier).name)
|
|
328
|
-
}
|
|
329
|
-
})
|
|
330
|
-
} else {
|
|
331
|
-
setScope(parentFunction, (node.id as Identifier).name)
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
},
|
|
336
|
-
|
|
337
|
-
leave(node: Node, parent: Node | null) {
|
|
338
|
-
parent && parentStack.pop()
|
|
339
|
-
const scopeIds = scopeMap.get(node)
|
|
340
|
-
if (scopeIds) {
|
|
341
|
-
scopeIds.forEach((id: string) => {
|
|
342
|
-
scope[id]--
|
|
343
|
-
if (scope[id] === 0) {
|
|
344
|
-
delete scope[id]
|
|
345
|
-
}
|
|
346
|
-
})
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
})
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
function isRefIdentifier(id: Identifier, parent: _Node, parentStack: _Node[]) {
|
|
353
|
-
// declaration id
|
|
354
|
-
if (
|
|
355
|
-
parent.type === 'CatchClause' ||
|
|
356
|
-
((parent.type === 'VariableDeclarator' ||
|
|
357
|
-
parent.type === 'ClassDeclaration') &&
|
|
358
|
-
parent.id === id)
|
|
359
|
-
) {
|
|
360
|
-
return false
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
if (isFunction(parent)) {
|
|
364
|
-
// function declaration/expression id
|
|
365
|
-
if ((parent as any).id === id) {
|
|
366
|
-
return false
|
|
367
|
-
}
|
|
368
|
-
// params list
|
|
369
|
-
if (parent.params.includes(id)) {
|
|
370
|
-
return false
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
// class method name
|
|
375
|
-
if (parent.type === 'MethodDefinition') {
|
|
376
|
-
return false
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
// property key
|
|
380
|
-
// this also covers object destructuring pattern
|
|
381
|
-
if (isStaticPropertyKey(id, parent) || (parent as any).inPattern) {
|
|
382
|
-
return false
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
// non-assignment array destructuring pattern
|
|
386
|
-
if (
|
|
387
|
-
parent.type === 'ArrayPattern' &&
|
|
388
|
-
!isInDestructuringAssignment(parent, parentStack)
|
|
389
|
-
) {
|
|
390
|
-
return false
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
// member expression property
|
|
394
|
-
if (
|
|
395
|
-
parent.type === 'MemberExpression' &&
|
|
396
|
-
parent.property === id &&
|
|
397
|
-
!parent.computed
|
|
398
|
-
) {
|
|
399
|
-
return false
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
if (parent.type === 'ExportSpecifier') {
|
|
403
|
-
return false
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
// is a special keyword but parsed as identifier
|
|
407
|
-
if (id.name === 'arguments') {
|
|
408
|
-
return false
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
return true
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
const isStaticProperty = (node: _Node): node is Property =>
|
|
415
|
-
node && node.type === 'Property' && !node.computed
|
|
416
|
-
|
|
417
|
-
const isStaticPropertyKey = (node: _Node, parent: _Node) =>
|
|
418
|
-
isStaticProperty(parent) && parent.key === node
|
|
419
|
-
|
|
420
|
-
function isFunction(node: _Node): node is FunctionNode {
|
|
421
|
-
return /Function(?:Expression|Declaration)$|Method$/.test(node.type)
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
function findParentFunction(parentStack: _Node[]): FunctionNode | undefined {
|
|
425
|
-
for (let i = parentStack.length - 1; i >= 0; i--) {
|
|
426
|
-
const node = parentStack[i]
|
|
427
|
-
if (isFunction(node)) {
|
|
428
|
-
return node
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
function isInDestructuringAssignment(
|
|
434
|
-
parent: _Node,
|
|
435
|
-
parentStack: _Node[]
|
|
436
|
-
): boolean {
|
|
437
|
-
if (
|
|
438
|
-
parent &&
|
|
439
|
-
(parent.type === 'Property' || parent.type === 'ArrayPattern')
|
|
440
|
-
) {
|
|
441
|
-
let i = parentStack.length
|
|
442
|
-
while (i--) {
|
|
443
|
-
const p = parentStack[i]
|
|
444
|
-
if (p.type === 'AssignmentExpression') {
|
|
445
|
-
return true
|
|
446
|
-
} else if (p.type !== 'Property' && !p.type.endsWith('Pattern')) {
|
|
447
|
-
break
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
return false
|
|
452
|
-
}
|
package/src/node/tsconfig.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.base.json",
|
|
3
|
-
"include": ["./", "../../types"],
|
|
4
|
-
"exclude": ["**/__tests__"],
|
|
5
|
-
"compilerOptions": {
|
|
6
|
-
// compile away optional-chaining-operator
|
|
7
|
-
// node support table: https://node.green/#ES2020-features-optional-chaining-operator-----
|
|
8
|
-
"target": "ES2019",
|
|
9
|
-
"outDir": "../../dist/node",
|
|
10
|
-
"module": "commonjs",
|
|
11
|
-
"lib": ["ESNext"],
|
|
12
|
-
"sourceMap": true
|
|
13
|
-
}
|
|
14
|
-
}
|