Skip to content

Commit d106157

Browse files
committed
Merge branch 'master' into sourceMap
2 parents 021c63f + fadd95f commit d106157

22 files changed

+455
-23
lines changed

src/compiler/builder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ namespace ts {
7878
if (useOldState) {
7979
// Verify the sanity of old state
8080
if (!oldState!.currentChangedFilePath) {
81-
Debug.assert(!oldState!.affectedFiles && (!oldState!.currentAffectedFilesSignatures || !oldState!.currentAffectedFilesSignatures!.size), "Cannot reuse if only few affected files of currentChangedFile were iterated");
81+
const affectedSignatures = oldState!.currentAffectedFilesSignatures;
82+
Debug.assert(!oldState!.affectedFiles && (!affectedSignatures || !affectedSignatures.size), "Cannot reuse if only few affected files of currentChangedFile were iterated");
8283
}
8384
if (canCopySemanticDiagnostics) {
8485
Debug.assert(!forEachKey(oldState!.changedFilesSet, path => oldState!.semanticDiagnosticsPerFile!.has(path)), "Semantic diagnostics shouldnt be available for changed files");

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4811,5 +4811,9 @@
48114811
"Add names to all parameters without names": {
48124812
"category": "Message",
48134813
"code": 95073
4814+
},
4815+
"Enable the 'experimentalDecorators' option in your configuration file": {
4816+
"category": "Message",
4817+
"code": 95074
48144818
}
48154819
}

src/compiler/emitter.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2561,6 +2561,7 @@ namespace ts {
25612561
function emitJsxSelfClosingElement(node: JsxSelfClosingElement) {
25622562
writePunctuation("<");
25632563
emitJsxTagName(node.tagName);
2564+
emitTypeArguments(node, node.typeArguments);
25642565
writeSpace();
25652566
emit(node.attributes);
25662567
writePunctuation("/>");
@@ -2577,6 +2578,7 @@ namespace ts {
25772578

25782579
if (isJsxOpeningElement(node)) {
25792580
emitJsxTagName(node.tagName);
2581+
emitTypeArguments(node, node.typeArguments);
25802582
if (node.attributes.properties && node.attributes.properties.length > 0) {
25812583
writeSpace();
25822584
}

src/compiler/parser.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7774,17 +7774,18 @@ namespace ts {
77747774
const libReferenceDirectives = context.libReferenceDirectives;
77757775
forEach(toArray(entryOrList), (arg: PragmaPseudoMap["reference"]) => {
77767776
// TODO: GH#18217
7777+
const { types, lib, path } = arg!.arguments;
77777778
if (arg!.arguments["no-default-lib"]) {
77787779
context.hasNoDefaultLib = true;
77797780
}
7780-
else if (arg!.arguments.types) {
7781-
typeReferenceDirectives.push({ pos: arg!.arguments.types!.pos, end: arg!.arguments.types!.end, fileName: arg!.arguments.types!.value });
7781+
else if (types) {
7782+
typeReferenceDirectives.push({ pos: types.pos, end: types.end, fileName: types.value });
77827783
}
7783-
else if (arg!.arguments.lib) {
7784-
libReferenceDirectives.push({ pos: arg!.arguments.lib!.pos, end: arg!.arguments.lib!.end, fileName: arg!.arguments.lib!.value });
7784+
else if (lib) {
7785+
libReferenceDirectives.push({ pos: lib.pos, end: lib.end, fileName: lib.value });
77857786
}
7786-
else if (arg!.arguments.path) {
7787-
referencedFiles.push({ pos: arg!.arguments.path!.pos, end: arg!.arguments.path!.end, fileName: arg!.arguments.path!.value });
7787+
else if (path) {
7788+
referencedFiles.push({ pos: path.pos, end: path.end, fileName: path.value });
77887789
}
77897790
else {
77907791
reportDiagnostic(arg!.range.pos, arg!.range.end - arg!.range.pos, Diagnostics.Invalid_reference_directive_syntax);

src/compiler/program.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,8 +2227,9 @@ namespace ts {
22272227
processReferencedFiles(file, isDefaultLib);
22282228
processTypeReferenceDirectives(file);
22292229
}
2230-
2231-
processLibReferenceDirectives(file);
2230+
if (!options.noLib) {
2231+
processLibReferenceDirectives(file);
2232+
}
22322233

22332234
modulesWithElidedImports.set(file.path, false);
22342235
processImportedModules(file);
@@ -2315,8 +2316,10 @@ namespace ts {
23152316
processReferencedFiles(file, isDefaultLib);
23162317
processTypeReferenceDirectives(file);
23172318
}
2319+
if (!options.noLib) {
2320+
processLibReferenceDirectives(file);
2321+
}
23182322

2319-
processLibReferenceDirectives(file);
23202323

23212324
// always process imported modules to record module name resolutions
23222325
processImportedModules(file);

src/harness/compiler.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,9 @@ namespace compiler {
183183
}
184184

185185
public getSourceMapRecord(): string | undefined {
186-
if (this.result!.sourceMaps && this.result!.sourceMaps!.length > 0) {
187-
return Harness.SourceMapRecorder.getSourceMapRecord(this.result!.sourceMaps!, this.program!, Array.from(this.js.values()).filter(d => !ts.fileExtensionIs(d.file, ts.Extension.Json)), Array.from(this.dts.values()));
186+
const maps = this.result!.sourceMaps;
187+
if (maps && maps.length > 0) {
188+
return Harness.SourceMapRecorder.getSourceMapRecord(maps, this.program!, Array.from(this.js.values()).filter(d => !ts.fileExtensionIs(d.file, ts.Extension.Json)), Array.from(this.dts.values()));
188189
}
189190
}
190191

src/services/codefixes/fixCannotFindModule.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ namespace ts.codefix {
7474
const tsconfigObjectLiteral = getTsConfigObjectLiteralExpression(configFile);
7575
if (!tsconfigObjectLiteral) return undefined;
7676

77-
const compilerOptionsProperty = findProperty(tsconfigObjectLiteral, "compilerOptions");
77+
const compilerOptionsProperty = findJsonProperty(tsconfigObjectLiteral, "compilerOptions");
7878
if (!compilerOptionsProperty) {
7979
const newCompilerOptions = createObjectLiteral([makeDefaultBaseUrl(), makeDefaultPaths()]);
8080
changes.insertNodeAtObjectStart(configFile, tsconfigObjectLiteral, createJsonPropertyAssignment("compilerOptions", newCompilerOptions));
@@ -94,7 +94,7 @@ namespace ts.codefix {
9494
return createJsonPropertyAssignment("baseUrl", createStringLiteral(defaultBaseUrl));
9595
}
9696
function getOrAddBaseUrl(changes: textChanges.ChangeTracker, tsconfig: TsConfigSourceFile, compilerOptions: ObjectLiteralExpression): string {
97-
const baseUrlProp = findProperty(compilerOptions, "baseUrl");
97+
const baseUrlProp = findJsonProperty(compilerOptions, "baseUrl");
9898
if (baseUrlProp) {
9999
return isStringLiteral(baseUrlProp.initializer) ? baseUrlProp.initializer.text : defaultBaseUrl;
100100
}
@@ -112,7 +112,7 @@ namespace ts.codefix {
112112
return createJsonPropertyAssignment("paths", createObjectLiteral([makeDefaultPathMapping()]));
113113
}
114114
function getOrAddPathMapping(changes: textChanges.ChangeTracker, tsconfig: TsConfigSourceFile, compilerOptions: ObjectLiteralExpression) {
115-
const paths = findProperty(compilerOptions, "paths");
115+
const paths = findJsonProperty(compilerOptions, "paths");
116116
if (!paths || !isObjectLiteralExpression(paths.initializer)) {
117117
changes.insertNodeAtObjectStart(tsconfig, compilerOptions, makeDefaultPaths());
118118
return defaultTypesDirectoryName;
@@ -129,14 +129,6 @@ namespace ts.codefix {
129129
return defaultTypesDirectoryName;
130130
}
131131

132-
function createJsonPropertyAssignment(name: string, initializer: Expression) {
133-
return createPropertyAssignment(createStringLiteral(name), initializer);
134-
}
135-
136-
function findProperty(obj: ObjectLiteralExpression, name: string): PropertyAssignment | undefined {
137-
return find(obj.properties, (p): p is PropertyAssignment => isPropertyAssignment(p) && !!p.name && isStringLiteral(p.name) && p.name.text === name);
138-
}
139-
140132
function getInstallCommand(fileName: string, packageName: string): InstallPackageAction {
141133
return { type: "install package", file: fileName, packageName };
142134
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* @internal */
2+
namespace ts.codefix {
3+
const fixId = "enableExperimentalDecorators";
4+
const errorCodes = [
5+
Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalDecorators_option_to_remove_this_warning.code
6+
];
7+
registerCodeFix({
8+
errorCodes,
9+
getCodeActions: (context) => {
10+
const { configFile } = context.program.getCompilerOptions();
11+
if (configFile === undefined) {
12+
return undefined;
13+
}
14+
15+
const changes = textChanges.ChangeTracker.with(context, changeTracker => makeChange(changeTracker, configFile));
16+
return [createCodeFixActionNoFixId(fixId, changes, Diagnostics.Enable_the_experimentalDecorators_option_in_your_configuration_file)];
17+
},
18+
fixIds: [fixId],
19+
});
20+
21+
function makeChange(changeTracker: textChanges.ChangeTracker, configFile: TsConfigSourceFile) {
22+
setJsonCompilerOptionValue(changeTracker, configFile, "experimentalDecorators", createTrue());
23+
}
24+
}

src/services/codefixes/helpers.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,46 @@ namespace ts.codefix {
249249
}
250250
return undefined;
251251
}
252+
253+
export function setJsonCompilerOptionValue(
254+
changeTracker: textChanges.ChangeTracker,
255+
configFile: TsConfigSourceFile,
256+
optionName: string,
257+
optionValue: Expression,
258+
) {
259+
const tsconfigObjectLiteral = getTsConfigObjectLiteralExpression(configFile);
260+
if (!tsconfigObjectLiteral) return undefined;
261+
262+
const compilerOptionsProperty = findJsonProperty(tsconfigObjectLiteral, "compilerOptions");
263+
if (compilerOptionsProperty === undefined) {
264+
changeTracker.insertNodeAtObjectStart(configFile, tsconfigObjectLiteral, createJsonPropertyAssignment(
265+
"compilerOptions",
266+
createObjectLiteral([
267+
createJsonPropertyAssignment(optionName, optionValue),
268+
])));
269+
return;
270+
}
271+
272+
const compilerOptions = compilerOptionsProperty.initializer;
273+
if (!isObjectLiteralExpression(compilerOptions)) {
274+
return;
275+
}
276+
277+
const optionProperty = findJsonProperty(compilerOptions, optionName);
278+
279+
if (optionProperty === undefined) {
280+
changeTracker.insertNodeAtObjectStart(configFile, compilerOptions, createJsonPropertyAssignment(optionName, optionValue));
281+
}
282+
else {
283+
changeTracker.replaceNode(configFile, optionProperty.initializer, optionValue);
284+
}
285+
}
286+
287+
export function createJsonPropertyAssignment(name: string, initializer: Expression) {
288+
return createPropertyAssignment(createStringLiteral(name), initializer);
289+
}
290+
291+
export function findJsonProperty(obj: ObjectLiteralExpression, name: string): PropertyAssignment | undefined {
292+
return find(obj.properties, (p): p is PropertyAssignment => isPropertyAssignment(p) && !!p.name && isStringLiteral(p.name) && p.name.text === name);
293+
}
252294
}

src/services/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"codefixes/fixClassDoesntImplementInheritedAbstractMember.ts",
6262
"codefixes/fixClassSuperMustPrecedeThisAccess.ts",
6363
"codefixes/fixConstructorForDerivedNeedSuperCall.ts",
64+
"codefixes/fixEnableExperimentalDecorators.ts",
6465
"codefixes/fixExtendsInterfaceBecomesImplements.ts",
6566
"codefixes/fixForgottenThisPropertyAccess.ts",
6667
"codefixes/fixUnusedIdentifier.ts",

0 commit comments

Comments
 (0)