-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Adding tsconfig.json mixed content (script block) support #12153
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
Changes from 5 commits
da7f824
7dd30db
891173c
464bc0e
12971d2
64dad30
1c3689e
7a11453
d528943
4cb5a36
5f46e48
05160ca
30bd841
5829ca8
c40508c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1942,8 +1942,16 @@ namespace ts { | |
export const supportedJavascriptExtensions = [".js", ".jsx"]; | ||
const allSupportedExtensions = supportedTypeScriptExtensions.concat(supportedJavascriptExtensions); | ||
|
||
export function getSupportedExtensions(options?: CompilerOptions): string[] { | ||
return options && options.allowJs ? allSupportedExtensions : supportedTypeScriptExtensions; | ||
export function getSupportedExtensions(options?: CompilerOptions, fileExtensionMap?: FileExtensionMap): string[] { | ||
let typeScriptHostExtensions: string[] = []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor nit to reduce allocations: let allExtensions: string[];
let allTypeScriptExtensions: string[];
const needAllExtensions = options && options.allowJs;
if (!extraFileExtensions) {
return needAllExtensions ? allSupportedExtensions : supportedTypeScriptExtensions;
}
const extensions = (needAllExtensions ? allSupportedExtensions : supportedTypeScriptExtensions).slice(0);
for (const ext of extraExtensions) {
if (!needAllExtensions || ext.scriptKind === ScriptKind.TS) {
extensions.push(ext.fileName);
}
}
return extensions; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clever - testing this change and will update |
||
let allHostExtensions: string[] = []; | ||
if (fileExtensionMap) { | ||
allHostExtensions = concatenate(concatenate(fileExtensionMap.javaScript, fileExtensionMap.typeScript), fileExtensionMap.mixedContent); | ||
typeScriptHostExtensions = fileExtensionMap.typeScript; | ||
} | ||
const allTypeScriptExtensions = concatenate(supportedTypeScriptExtensions, typeScriptHostExtensions); | ||
const allExtensions = concatenate(allSupportedExtensions, allHostExtensions); | ||
return options && options.allowJs ? allExtensions : allTypeScriptExtensions; | ||
} | ||
|
||
export function hasJavaScriptFileExtension(fileName: string) { | ||
|
@@ -1954,10 +1962,10 @@ namespace ts { | |
return forEach(supportedTypeScriptExtensions, extension => fileExtensionIs(fileName, extension)); | ||
} | ||
|
||
export function isSupportedSourceFileName(fileName: string, compilerOptions?: CompilerOptions) { | ||
export function isSupportedSourceFileName(fileName: string, compilerOptions?: CompilerOptions, fileExtensionMap?: FileExtensionMap) { | ||
if (!fileName) { return false; } | ||
|
||
for (const extension of getSupportedExtensions(compilerOptions)) { | ||
for (const extension of getSupportedExtensions(compilerOptions, fileExtensionMap)) { | ||
if (fileExtensionIs(fileName, extension)) { | ||
return true; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -285,7 +285,7 @@ namespace ts { | |
return resolutions; | ||
} | ||
|
||
export function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program): Program { | ||
export function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program, fileExtensionMap?: FileExtensionMap): Program { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need to push concrete knowledge about these extra extensions through all layers, this will be necessary if we'll need to be able to add files with these extensions into program via imports or tripleslash references. Since both these scenarios are not supported and files with custom extensions should always be included in the list of root files I think we can:
this way I think we can update only project system part and keep all other layers relatively untouched. |
||
let program: Program; | ||
let files: SourceFile[] = []; | ||
let commonSourceDirectory: string; | ||
|
@@ -320,7 +320,7 @@ namespace ts { | |
let skipDefaultLib = options.noLib; | ||
const programDiagnostics = createDiagnosticCollection(); | ||
const currentDirectory = host.getCurrentDirectory(); | ||
const supportedExtensions = getSupportedExtensions(options); | ||
const supportedExtensions = getSupportedExtensions(options, fileExtensionMap); | ||
|
||
// Map storing if there is emit blocking diagnostics for given input | ||
const hasEmitBlockingDiagnostics = createFileMap<boolean>(getCanonicalFileName); | ||
|
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.
is it not really a map anymore. maybe
extraExtensions: ExtensionInfo[]
?Uh oh!
There was an error while loading. Please reload this page.
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.
sounds good - will switch to extraFileExtensions: FileExtensionInfo[]