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

Implement #35656 #1

Merged
merged 1 commit into from
Dec 19, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,18 +273,7 @@ namespace ts {
{
name: "target",
shortName: "t",
type: createMapFromTemplate({
es3: ScriptTarget.ES3,
es5: ScriptTarget.ES5,
es6: ScriptTarget.ES2015,
es2015: ScriptTarget.ES2015,
es2016: ScriptTarget.ES2016,
es2017: ScriptTarget.ES2017,
es2018: ScriptTarget.ES2018,
es2019: ScriptTarget.ES2019,
es2020: ScriptTarget.ES2020,
esnext: ScriptTarget.ESNext,
}),
type: ScriptTargetMap,
affectsSourceFile: true,
affectsModuleResolution: true,
affectsEmit: true,
Expand Down
13 changes: 13 additions & 0 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8186,6 +8186,19 @@ namespace ts {
});
break;
}
case "compilerOptions": {
forEach(toArray(entryOrList), entry => {
// _last_ compilerOptions target value in a file is the "winner"
const targetKey = (entry as PragmaPseudoMap["compilerOptions"]).arguments.target;
if (ScriptTargetMap.has(targetKey)) {
context.languageVersion = ScriptTargetMap.get(targetKey) as ScriptTarget;
}
else {
Debug.fail(`Unrecognized compilerOptions target in XML pragma: ${targetKey}`);
}
});
break;
}
case "jsx": return; // Accessed directly
default: Debug.fail("Unhandled pragma kind"); // Can this be made into an assertNever in the future?
}
Expand Down
18 changes: 18 additions & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5163,6 +5163,20 @@ namespace ts {
Latest = ESNext,
}

export const ScriptTargetMap = createMapFromTemplate({
es3: ScriptTarget.ES3,
es5: ScriptTarget.ES5,
es6: ScriptTarget.ES2015,
es2015: ScriptTarget.ES2015,
es2016: ScriptTarget.ES2016,
es2017: ScriptTarget.ES2017,
es2018: ScriptTarget.ES2018,
es2019: ScriptTarget.ES2019,
es2020: ScriptTarget.ES2020,
esnext: ScriptTarget.ESNext,
});
Object.freeze(ScriptTargetMap);

export const enum LanguageVariant {
Standard,
JSX
Expand Down Expand Up @@ -6454,6 +6468,10 @@ namespace ts {
args: [{ name: "name" }],
kind: PragmaKindFlags.TripleSlashXML
},
"compilerOptions": {
args: [{ name: "target" }],
kind: PragmaKindFlags.TripleSlashXML
},
"ts-check": {
kind: PragmaKindFlags.SingleLine
},
Expand Down