Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update es-module-lexer #7357

Merged
merged 1 commit into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vite/LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ Repository: git+https://github.com/guybedford/es-module-lexer.git
> MIT License
> -----------
>
> Copyright (C) 2018-2021 Guy Bedford
> Copyright (C) 2018-2022 Guy Bedford
>
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
>
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"debug": "^4.3.3",
"dotenv": "^14.3.2",
"dotenv-expand": "^5.1.0",
"es-module-lexer": "~0.9.3",
"es-module-lexer": "^0.10.1",
"estree-walker": "^2.0.2",
"etag": "^1.8.1",
"fast-glob": "^3.2.11",
Expand Down
6 changes: 3 additions & 3 deletions packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
continue
}

const isDynamicImport = dynamicIndex >= 0
const isDynamicImport = dynamicIndex > -1

// static import or valid string in dynamic import
// If resolvable, let's resolve it
Expand Down Expand Up @@ -466,8 +466,8 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
if (isDynamicImport) {
// rewrite `import('package')` to expose the default directly
str().overwrite(
dynamicIndex,
end + 1,
expStart,
expEnd,
`import('${url}').then(m => m.default && m.default.__esModule ? m.default : ({ ...m.default, default: m.default }))`
)
} else {
Expand Down
11 changes: 6 additions & 5 deletions packages/vite/src/node/plugins/importAnalysisBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
s: start,
e: end,
ss: expStart,
se: expEnd,
n: specifier,
d: dynamicIndex
} = imports[index]
Expand Down Expand Up @@ -173,10 +174,9 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {

if (dynamicIndex > -1 && insertPreload) {
needPreloadHelper = true
const dynamicEnd = source.indexOf(`)`, end) + 1
const original = source.slice(dynamicIndex, dynamicEnd)
const original = source.slice(expStart, expEnd)
const replacement = `${preloadMethod}(() => ${original},${isModernFlag}?"${preloadMarker}":void 0)`
str().overwrite(dynamicIndex, dynamicEnd, replacement)
str().overwrite(expStart, expEnd, replacement)
}

// Differentiate CSS imports that use the default export from those that
Expand Down Expand Up @@ -263,7 +263,8 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
n: name,
s: start,
e: end,
d: dynamicIndex
ss: expStart,
se: expEnd
} = imports[index]
// check the chunk being imported
let url = name
Expand Down Expand Up @@ -302,7 +303,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
hasRemovedPureCssChunk = true
}

s.overwrite(dynamicIndex, end + 1, 'Promise.resolve({})')
s.overwrite(expStart, expEnd, 'Promise.resolve({})')
}
}
}
Expand Down
51 changes: 22 additions & 29 deletions packages/vite/src/node/ssr/ssrManifestPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,37 +45,30 @@ export function ssrManifestPlugin(config: ResolvedConfig): Plugin {
}
if (imports.length) {
for (let index = 0; index < imports.length; index++) {
const {
s: start,
e: end,
n: name,
d: dynamicIndex
} = imports[index]
if (dynamicIndex) {
// check the chunk being imported
const url = code.slice(start, end)
const deps: string[] = []
const ownerFilename = chunk.fileName
// literal import - trace direct imports and add to deps
const analyzed: Set<string> = new Set<string>()
const addDeps = (filename: string) => {
if (filename === ownerFilename) return
if (analyzed.has(filename)) return
analyzed.add(filename)
const chunk = bundle[filename] as OutputChunk | undefined
if (chunk) {
chunk.viteMetadata.importedCss.forEach((file) => {
deps.push(`/${file}`)
})
chunk.imports.forEach(addDeps)
}
const { s: start, e: end, n: name } = imports[index]
// check the chunk being imported
const url = code.slice(start, end)
const deps: string[] = []
const ownerFilename = chunk.fileName
// literal import - trace direct imports and add to deps
const analyzed: Set<string> = new Set<string>()
const addDeps = (filename: string) => {
if (filename === ownerFilename) return
if (analyzed.has(filename)) return
analyzed.add(filename)
const chunk = bundle[filename] as OutputChunk | undefined
if (chunk) {
chunk.viteMetadata.importedCss.forEach((file) => {
deps.push(`/${file}`)
})
chunk.imports.forEach(addDeps)
}
const normalizedFile = normalizePath(
join(dirname(chunk.fileName), url.slice(1, -1))
)
addDeps(normalizedFile)
ssrManifest[basename(name!)] = deps
}
const normalizedFile = normalizePath(
join(dirname(chunk.fileName), url.slice(1, -1))
)
addDeps(normalizedFile)
ssrManifest[basename(name!)] = deps
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.