| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| export const compileOnSaveCommandLineOption: CommandLineOption = { name: "compileOnSave", type: "boolean" }; | ||
|
|
||
| /* @internal */ | ||
| export const libMap = createMapFromTemplate({ |
There was a problem hiding this comment.
This just maps x to lib.x.d.ts. Could be a function instead, combined with a set of allowed libs.
Sorry, something went wrong.
There was a problem hiding this comment.
This must be a Map to be used in the compiler option I pulled it from, below. If I added a function then we would have yet another place to maintain this list (in addition to the jakefile/gulpfile).
Sorry, something went wrong.
There was a problem hiding this comment.
It would still be nice to generate this instead of writing it explicitly. Start with const libs = ["es5", ..., "esnext.asynciterable"], generate the map with lib.${x}.d.ts, and you'll no longer need to use arrayFrom(libMap.keys()).
Sorry, something went wrong.
There was a problem hiding this comment.
Except for the outliers like "es6" and "es7" which are aliases.
Sorry, something went wrong.
There was a problem hiding this comment.
Alternatively, we leave libMap as is, and add: export const libs = arrayFrom(libMap.keys());
Sorry, something went wrong.
| @@ -9,6 +9,7 @@ namespace ts { | |||
| diagnosticMessage?: DiagnosticMessage; | |||
| isNoDefaultLib?: boolean; | |||
There was a problem hiding this comment.
These three should really be kind?: "no-default-lib" | "types" | "lib".
Sorry, something went wrong.
There was a problem hiding this comment.
Agreed.
Sorry, something went wrong.
There was a problem hiding this comment.
Or kind: "no-default-lib" | "path" | "types" | "lib".
Sorry, something went wrong.
| function processLibReferenceDirectives(file: SourceFile) { | ||
| const libDirectory = getLibDirectory(); | ||
| forEach(file.libReferenceDirectives, libReference => { | ||
| const libName = libReference.fileName.toLocaleLowerCase(); |
There was a problem hiding this comment.
Do we really need to lower-case it? If they try accessing /// <reference lib="es2017.Object" /> we will correct their spelling to "es2017.object".
Sorry, something went wrong.
There was a problem hiding this comment.
That's what we do for --lib, so its consistent.
Sorry, something went wrong.
| export function getFileReferenceFromReferencePath(comment: string, commentRange: CommentRange): ReferencePathMatchResult { | ||
| const simpleReferenceRegEx = /^\/\/\/\s*<reference\s+/gim; | ||
| const isNoDefaultLibRegEx = /^(\/\/\/\s*<reference\s+no-default-lib\s*=\s*)('|")(.+?)\2\s*\/>/gim; | ||
| if (simpleReferenceRegEx.test(comment)) { |
There was a problem hiding this comment.
Good place for an early return.
Sorry, something went wrong.
|
We'll also want to support services (goto definition at least, find-all-references isn't as important) on these, but that should wait for after both this and #15737 are in. |
Sorry, something went wrong.
There was a problem hiding this comment.
The ignoreNoDefaultLib parameter is never provided the value true. Is it needed?
Sorry, something went wrong.
| */ | ||
| export function getSpellingSuggestion<T>(name: string, choices: T[], exclusions: string[] | undefined, getName: (candidate: T) => string | undefined): T | undefined; | ||
| export function getSpellingSuggestion<T>(name: string, choices: T[], exclusions?: string[], getName: (candidate: T) => string | undefined = identity): T | undefined { | ||
| // If there is a candidate that's the same except for case, return that. |
There was a problem hiding this comment.
Can you move this back to the JSDoc?
Sorry, something went wrong.
There was a problem hiding this comment.
I didn't want to repeat the rather lengthy description for both overloads, and its a lot of text to show when you mouse over a reference. Its too bad we don't support the @summary jsdoc tag.
Sorry, something went wrong.
There was a problem hiding this comment.
Ouch. I didn't realise that both overloads had separate jsdoc. And @summary is exactly what I was thinking of. Isn't there the opposite, something like @remarks ? (Later: nope, I guess I am thinking of XML doc comments in C#)
Sorry, something went wrong.
| } | ||
| else { | ||
| const libDirectory = host.getDefaultLibLocation ? host.getDefaultLibLocation() : getDirectoryPath(host.getDefaultLibFileName(options)); | ||
| const libDirectory = getLibDirectory(); |
There was a problem hiding this comment.
this shadows the outer libDirectory. Can you change it so that the code is less confusing?
Sorry, something went wrong.
| const libFileName = libMap.get(libName); | ||
| if (libFileName) { | ||
| // we ignore any 'no-default-lib' reference set on this import. | ||
| processRootFile(combinePaths(libDirectory, libFileName), /*isDefaultLib*/ true, /*ignoreNoDefaultLib*/ false); |
There was a problem hiding this comment.
shouldn't be ignoreNoDefaultLib be true in order to ignore 'no-default-lib' references?
Sorry, something went wrong.
There was a problem hiding this comment.
Yes it should.
Sorry, something went wrong.
There was a problem hiding this comment.
Shouldn't flipping false to true for ignoreNoDefaultLib in the last commit change some tests?
Sorry, something went wrong.
|
Nathan Shively-Sanders (@sandersn) There wasn't a good test to capture that case. I've added one as of the last commit (47ed6cc). |
Sorry, something went wrong.
|
Anders Hejlsberg (@ahejlsberg): per your comments in the design meeting, this should now be loading each file only once. This means that lib.d.ts and lib.es6.d.ts are no longer concatenated, but instead use lib references to the files that compose them. See src/lib/default.es5.d.ts for an example of the file that is now used to build lib.d.ts. |
Sorry, something went wrong.
|
This came up today in Google style discussion, are you still planning to land this? |
Sorry, something went wrong.
|
Daniel Rosenwasser (@DanielRosenwasser) we discussed this one next week, would still be nice to be able to use this for our BUILD.bazel file generator (in cases where we require libs to be declared dependencies) |
Sorry, something went wrong.
|
Any progress on this? |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
This change adds support for a /// <reference lib="name" /> directive, allowing a file to explicitly include an existing built-in lib file.
In the long term this can help polyfill/shim packages like core-js or es6-shim.
Fixes #15732.