-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
fix: missing types for es-module-lexer
(fixes #8349)
#8352
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,20 @@ | ||
{ | ||
"compilerOptions": { | ||
"noEmit": true, | ||
"moduleResolution": "classic", | ||
// Only add entries to `paths` when you are adding/updating dependencies (not devDependencies) | ||
// See CONTRIBUTING.md "Ensure type support" for more details | ||
"paths": { | ||
// direct | ||
"rollup": ["./node_modules/rollup/dist/rollup.d.ts"], | ||
// direct | ||
"esbuild": ["./node_modules/esbuild/lib/main.d.ts"], | ||
// direct | ||
"postcss": ["./node_modules/postcss/lib/postcss.d.ts"], | ||
// indirect: postcss depends on it | ||
"source-map-js": ["./node_modules/source-map-js/source-map.d.ts"] | ||
}, | ||
"typeRoots": [] | ||
}, | ||
"include": ["dist/**/*.d.ts"] | ||
} |
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,90 @@ | ||
// Modified and inlined to avoid extra dependency | ||
// Source: https://github.com/guybedford/es-module-lexer/blob/main/types/lexer.d.ts | ||
// MIT Licensed https://github.com/guybedford/es-module-lexer/blob/main/LICENSE | ||
|
||
export interface ImportSpecifier { | ||
/** | ||
* Module name | ||
* | ||
* To handle escape sequences in specifier strings, the .n field of imported specifiers will be provided where possible. | ||
* | ||
* For dynamic import expressions, this field will be empty if not a valid JS string. | ||
* | ||
* @example | ||
* const [imports1, exports1] = parse(String.raw`import './\u0061\u0062.js'`); | ||
* imports1[0].n; | ||
* // Returns "./ab.js" | ||
* | ||
* const [imports2, exports2] = parse(`import("./ab.js")`); | ||
* imports2[0].n; | ||
* // Returns "./ab.js" | ||
* | ||
* const [imports3, exports3] = parse(`import("./" + "ab.js")`); | ||
* imports3[0].n; | ||
* // Returns undefined | ||
*/ | ||
readonly n: string | undefined | ||
/** | ||
* Start of module specifier | ||
* | ||
* @example | ||
* const source = `import { a } from 'asdf'`; | ||
* const [imports, exports] = parse(source); | ||
* source.substring(imports[0].s, imports[0].e); | ||
* // Returns "asdf" | ||
*/ | ||
readonly s: number | ||
/** | ||
* End of module specifier | ||
*/ | ||
readonly e: number | ||
|
||
/** | ||
* Start of import statement | ||
* | ||
* @example | ||
* const source = `import { a } from 'asdf'`; | ||
* const [imports, exports] = parse(source); | ||
* source.substring(imports[0].ss, imports[0].se); | ||
* // Returns `"import { a } from 'asdf';"` | ||
*/ | ||
readonly ss: number | ||
/** | ||
* End of import statement | ||
*/ | ||
readonly se: number | ||
|
||
/** | ||
* If this import statement is a dynamic import, this is the start value. | ||
* Otherwise this is `-1`. | ||
*/ | ||
readonly d: number | ||
|
||
/** | ||
* If this import has an import assertion, this is the start value. | ||
* Otherwise this is `-1`. | ||
*/ | ||
readonly a: number | ||
} | ||
|
||
/** | ||
* Wait for init to resolve before calling `parse`. | ||
*/ | ||
export const init: Promise<void> | ||
|
||
/** | ||
* Outputs the list of exports and locations of import specifiers, | ||
* including dynamic import and import meta handling. | ||
* | ||
* @param source - Source code to parser | ||
* @param name - Optional sourcename | ||
* @returns Tuple contaning imports list and exports list. | ||
*/ | ||
export function parse( | ||
source: string, | ||
name?: string | ||
): readonly [ | ||
imports: ReadonlyArray<ImportSpecifier>, | ||
exports: ReadonlyArray<string>, | ||
facade: boolean | ||
] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These needs to be exported because it is included in the return type of
vite.optimize
.But are these needs to be exported? (I didnt check closely yet)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also export them to be safe, and then we remove them in another PR if they are unneeded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll check it and create a new PR if I felt it won't be needed 👍