Merge branch 'master' into sourceMap

This commit is contained in:
Sheetal Nandi 2019-01-11 14:47:24 -08:00
commit d1061579d3
22 changed files with 455 additions and 23 deletions

View File

@ -78,7 +78,8 @@ namespace ts {
if (useOldState) {
// Verify the sanity of old state
if (!oldState!.currentChangedFilePath) {
Debug.assert(!oldState!.affectedFiles && (!oldState!.currentAffectedFilesSignatures || !oldState!.currentAffectedFilesSignatures!.size), "Cannot reuse if only few affected files of currentChangedFile were iterated");
const affectedSignatures = oldState!.currentAffectedFilesSignatures;
Debug.assert(!oldState!.affectedFiles && (!affectedSignatures || !affectedSignatures.size), "Cannot reuse if only few affected files of currentChangedFile were iterated");
}
if (canCopySemanticDiagnostics) {
Debug.assert(!forEachKey(oldState!.changedFilesSet, path => oldState!.semanticDiagnosticsPerFile!.has(path)), "Semantic diagnostics shouldnt be available for changed files");

View File

@ -4811,5 +4811,9 @@
"Add names to all parameters without names": {
"category": "Message",
"code": 95073
},
"Enable the 'experimentalDecorators' option in your configuration file": {
"category": "Message",
"code": 95074
}
}

View File

@ -2561,6 +2561,7 @@ namespace ts {
function emitJsxSelfClosingElement(node: JsxSelfClosingElement) {
writePunctuation("<");
emitJsxTagName(node.tagName);
emitTypeArguments(node, node.typeArguments);
writeSpace();
emit(node.attributes);
writePunctuation("/>");
@ -2577,6 +2578,7 @@ namespace ts {
if (isJsxOpeningElement(node)) {
emitJsxTagName(node.tagName);
emitTypeArguments(node, node.typeArguments);
if (node.attributes.properties && node.attributes.properties.length > 0) {
writeSpace();
}

View File

@ -7774,17 +7774,18 @@ namespace ts {
const libReferenceDirectives = context.libReferenceDirectives;
forEach(toArray(entryOrList), (arg: PragmaPseudoMap["reference"]) => {
// TODO: GH#18217
const { types, lib, path } = arg!.arguments;
if (arg!.arguments["no-default-lib"]) {
context.hasNoDefaultLib = true;
}
else if (arg!.arguments.types) {
typeReferenceDirectives.push({ pos: arg!.arguments.types!.pos, end: arg!.arguments.types!.end, fileName: arg!.arguments.types!.value });
else if (types) {
typeReferenceDirectives.push({ pos: types.pos, end: types.end, fileName: types.value });
}
else if (arg!.arguments.lib) {
libReferenceDirectives.push({ pos: arg!.arguments.lib!.pos, end: arg!.arguments.lib!.end, fileName: arg!.arguments.lib!.value });
else if (lib) {
libReferenceDirectives.push({ pos: lib.pos, end: lib.end, fileName: lib.value });
}
else if (arg!.arguments.path) {
referencedFiles.push({ pos: arg!.arguments.path!.pos, end: arg!.arguments.path!.end, fileName: arg!.arguments.path!.value });
else if (path) {
referencedFiles.push({ pos: path.pos, end: path.end, fileName: path.value });
}
else {
reportDiagnostic(arg!.range.pos, arg!.range.end - arg!.range.pos, Diagnostics.Invalid_reference_directive_syntax);

View File

@ -2227,8 +2227,9 @@ namespace ts {
processReferencedFiles(file, isDefaultLib);
processTypeReferenceDirectives(file);
}
processLibReferenceDirectives(file);
if (!options.noLib) {
processLibReferenceDirectives(file);
}
modulesWithElidedImports.set(file.path, false);
processImportedModules(file);
@ -2315,8 +2316,10 @@ namespace ts {
processReferencedFiles(file, isDefaultLib);
processTypeReferenceDirectives(file);
}
if (!options.noLib) {
processLibReferenceDirectives(file);
}
processLibReferenceDirectives(file);
// always process imported modules to record module name resolutions
processImportedModules(file);

View File

@ -183,8 +183,9 @@ namespace compiler {
}
public getSourceMapRecord(): string | undefined {
if (this.result!.sourceMaps && this.result!.sourceMaps!.length > 0) {
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()));
const maps = this.result!.sourceMaps;
if (maps && maps.length > 0) {
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()));
}
}

View File

@ -74,7 +74,7 @@ namespace ts.codefix {
const tsconfigObjectLiteral = getTsConfigObjectLiteralExpression(configFile);
if (!tsconfigObjectLiteral) return undefined;
const compilerOptionsProperty = findProperty(tsconfigObjectLiteral, "compilerOptions");
const compilerOptionsProperty = findJsonProperty(tsconfigObjectLiteral, "compilerOptions");
if (!compilerOptionsProperty) {
const newCompilerOptions = createObjectLiteral([makeDefaultBaseUrl(), makeDefaultPaths()]);
changes.insertNodeAtObjectStart(configFile, tsconfigObjectLiteral, createJsonPropertyAssignment("compilerOptions", newCompilerOptions));
@ -94,7 +94,7 @@ namespace ts.codefix {
return createJsonPropertyAssignment("baseUrl", createStringLiteral(defaultBaseUrl));
}
function getOrAddBaseUrl(changes: textChanges.ChangeTracker, tsconfig: TsConfigSourceFile, compilerOptions: ObjectLiteralExpression): string {
const baseUrlProp = findProperty(compilerOptions, "baseUrl");
const baseUrlProp = findJsonProperty(compilerOptions, "baseUrl");
if (baseUrlProp) {
return isStringLiteral(baseUrlProp.initializer) ? baseUrlProp.initializer.text : defaultBaseUrl;
}
@ -112,7 +112,7 @@ namespace ts.codefix {
return createJsonPropertyAssignment("paths", createObjectLiteral([makeDefaultPathMapping()]));
}
function getOrAddPathMapping(changes: textChanges.ChangeTracker, tsconfig: TsConfigSourceFile, compilerOptions: ObjectLiteralExpression) {
const paths = findProperty(compilerOptions, "paths");
const paths = findJsonProperty(compilerOptions, "paths");
if (!paths || !isObjectLiteralExpression(paths.initializer)) {
changes.insertNodeAtObjectStart(tsconfig, compilerOptions, makeDefaultPaths());
return defaultTypesDirectoryName;
@ -129,14 +129,6 @@ namespace ts.codefix {
return defaultTypesDirectoryName;
}
function createJsonPropertyAssignment(name: string, initializer: Expression) {
return createPropertyAssignment(createStringLiteral(name), initializer);
}
function findProperty(obj: ObjectLiteralExpression, name: string): PropertyAssignment | undefined {
return find(obj.properties, (p): p is PropertyAssignment => isPropertyAssignment(p) && !!p.name && isStringLiteral(p.name) && p.name.text === name);
}
function getInstallCommand(fileName: string, packageName: string): InstallPackageAction {
return { type: "install package", file: fileName, packageName };
}

View File

@ -0,0 +1,24 @@
/* @internal */
namespace ts.codefix {
const fixId = "enableExperimentalDecorators";
const errorCodes = [
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
];
registerCodeFix({
errorCodes,
getCodeActions: (context) => {
const { configFile } = context.program.getCompilerOptions();
if (configFile === undefined) {
return undefined;
}
const changes = textChanges.ChangeTracker.with(context, changeTracker => makeChange(changeTracker, configFile));
return [createCodeFixActionNoFixId(fixId, changes, Diagnostics.Enable_the_experimentalDecorators_option_in_your_configuration_file)];
},
fixIds: [fixId],
});
function makeChange(changeTracker: textChanges.ChangeTracker, configFile: TsConfigSourceFile) {
setJsonCompilerOptionValue(changeTracker, configFile, "experimentalDecorators", createTrue());
}
}

View File

@ -249,4 +249,46 @@ namespace ts.codefix {
}
return undefined;
}
export function setJsonCompilerOptionValue(
changeTracker: textChanges.ChangeTracker,
configFile: TsConfigSourceFile,
optionName: string,
optionValue: Expression,
) {
const tsconfigObjectLiteral = getTsConfigObjectLiteralExpression(configFile);
if (!tsconfigObjectLiteral) return undefined;
const compilerOptionsProperty = findJsonProperty(tsconfigObjectLiteral, "compilerOptions");
if (compilerOptionsProperty === undefined) {
changeTracker.insertNodeAtObjectStart(configFile, tsconfigObjectLiteral, createJsonPropertyAssignment(
"compilerOptions",
createObjectLiteral([
createJsonPropertyAssignment(optionName, optionValue),
])));
return;
}
const compilerOptions = compilerOptionsProperty.initializer;
if (!isObjectLiteralExpression(compilerOptions)) {
return;
}
const optionProperty = findJsonProperty(compilerOptions, optionName);
if (optionProperty === undefined) {
changeTracker.insertNodeAtObjectStart(configFile, compilerOptions, createJsonPropertyAssignment(optionName, optionValue));
}
else {
changeTracker.replaceNode(configFile, optionProperty.initializer, optionValue);
}
}
export function createJsonPropertyAssignment(name: string, initializer: Expression) {
return createPropertyAssignment(createStringLiteral(name), initializer);
}
export function findJsonProperty(obj: ObjectLiteralExpression, name: string): PropertyAssignment | undefined {
return find(obj.properties, (p): p is PropertyAssignment => isPropertyAssignment(p) && !!p.name && isStringLiteral(p.name) && p.name.text === name);
}
}

View File

@ -61,6 +61,7 @@
"codefixes/fixClassDoesntImplementInheritedAbstractMember.ts",
"codefixes/fixClassSuperMustPrecedeThisAccess.ts",
"codefixes/fixConstructorForDerivedNeedSuperCall.ts",
"codefixes/fixEnableExperimentalDecorators.ts",
"codefixes/fixExtendsInterfaceBecomesImplements.ts",
"codefixes/fixForgottenThisPropertyAccess.ts",
"codefixes/fixUnusedIdentifier.ts",

View File

@ -0,0 +1,51 @@
//// [tests/cases/conformance/declarationEmit/libReferenceNoLib.ts] ////
//// [fakelib.ts]
// Test that passing noLib disables <reference lib> resolution.
interface Object { }
interface Array<T> { }
interface String { }
interface Boolean { }
interface Number { }
interface Function { }
interface RegExp { }
interface IArguments { }
//// [file1.ts]
/// <reference lib="dom" />
export declare interface HTMLElement { field: string; }
export const elem: HTMLElement = { field: 'a' };
//// [fakelib.js]
// Test that passing noLib disables <reference lib> resolution.
//// [file1.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.elem = { field: 'a' };
//// [fakelib.d.ts]
interface Object {
}
interface Array<T> {
}
interface String {
}
interface Boolean {
}
interface Number {
}
interface Function {
}
interface RegExp {
}
interface IArguments {
}
//// [file1.d.ts]
export declare interface HTMLElement {
field: string;
}
export declare const elem: HTMLElement;

View File

@ -0,0 +1,40 @@
=== tests/cases/conformance/declarationEmit/fakelib.ts ===
// Test that passing noLib disables <reference lib> resolution.
interface Object { }
>Object : Symbol(Object, Decl(fakelib.ts, 0, 0))
interface Array<T> { }
>Array : Symbol(Array, Decl(fakelib.ts, 2, 20))
>T : Symbol(T, Decl(fakelib.ts, 3, 16))
interface String { }
>String : Symbol(String, Decl(fakelib.ts, 3, 22))
interface Boolean { }
>Boolean : Symbol(Boolean, Decl(fakelib.ts, 4, 20))
interface Number { }
>Number : Symbol(Number, Decl(fakelib.ts, 5, 21))
interface Function { }
>Function : Symbol(Function, Decl(fakelib.ts, 6, 20))
interface RegExp { }
>RegExp : Symbol(RegExp, Decl(fakelib.ts, 7, 22))
interface IArguments { }
>IArguments : Symbol(IArguments, Decl(fakelib.ts, 8, 20))
=== tests/cases/conformance/declarationEmit/file1.ts ===
/// <reference lib="dom" />
export declare interface HTMLElement { field: string; }
>HTMLElement : Symbol(HTMLElement, Decl(file1.ts, 0, 0))
>field : Symbol(HTMLElement.field, Decl(file1.ts, 1, 38))
export const elem: HTMLElement = { field: 'a' };
>elem : Symbol(elem, Decl(file1.ts, 2, 12))
>HTMLElement : Symbol(HTMLElement, Decl(file1.ts, 0, 0))
>field : Symbol(field, Decl(file1.ts, 2, 34))

View File

@ -0,0 +1,24 @@
=== tests/cases/conformance/declarationEmit/fakelib.ts ===
// Test that passing noLib disables <reference lib> resolution.
No type information for this code.
No type information for this code.interface Object { }
No type information for this code.interface Array<T> { }
No type information for this code.interface String { }
No type information for this code.interface Boolean { }
No type information for this code.interface Number { }
No type information for this code.interface Function { }
No type information for this code.interface RegExp { }
No type information for this code.interface IArguments { }
No type information for this code.
No type information for this code.
No type information for this code.=== tests/cases/conformance/declarationEmit/file1.ts ===
/// <reference lib="dom" />
export declare interface HTMLElement { field: string; }
>field : string
export const elem: HTMLElement = { field: 'a' };
>elem : HTMLElement
>{ field: 'a' } : { field: string; }
>field : string
>'a' : "a"

View File

@ -0,0 +1,53 @@
//// [tests/cases/conformance/declarationEmit/libReferenceNoLibBundle.ts] ////
//// [fakelib.ts]
// Test that passing noLib disables <reference lib> resolution.
interface Object { }
interface Array<T> { }
interface String { }
interface Boolean { }
interface Number { }
interface Function { }
interface RegExp { }
interface IArguments { }
//// [file1.ts]
/// <reference lib="dom" />
export declare interface HTMLElement { field: string; }
export const elem: HTMLElement = { field: 'a' };
//// [bundle.js]
// Test that passing noLib disables <reference lib> resolution.
define("file1", ["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.elem = { field: 'a' };
});
//// [bundle.d.ts]
interface Object {
}
interface Array<T> {
}
interface String {
}
interface Boolean {
}
interface Number {
}
interface Function {
}
interface RegExp {
}
interface IArguments {
}
declare module "file1" {
export interface HTMLElement {
field: string;
}
export const elem: HTMLElement;
}

View File

@ -0,0 +1,40 @@
=== tests/cases/conformance/declarationEmit/fakelib.ts ===
// Test that passing noLib disables <reference lib> resolution.
interface Object { }
>Object : Symbol(Object, Decl(fakelib.ts, 0, 0))
interface Array<T> { }
>Array : Symbol(Array, Decl(fakelib.ts, 2, 20))
>T : Symbol(T, Decl(fakelib.ts, 3, 16))
interface String { }
>String : Symbol(String, Decl(fakelib.ts, 3, 22))
interface Boolean { }
>Boolean : Symbol(Boolean, Decl(fakelib.ts, 4, 20))
interface Number { }
>Number : Symbol(Number, Decl(fakelib.ts, 5, 21))
interface Function { }
>Function : Symbol(Function, Decl(fakelib.ts, 6, 20))
interface RegExp { }
>RegExp : Symbol(RegExp, Decl(fakelib.ts, 7, 22))
interface IArguments { }
>IArguments : Symbol(IArguments, Decl(fakelib.ts, 8, 20))
=== tests/cases/conformance/declarationEmit/file1.ts ===
/// <reference lib="dom" />
export declare interface HTMLElement { field: string; }
>HTMLElement : Symbol(HTMLElement, Decl(file1.ts, 0, 0))
>field : Symbol(HTMLElement.field, Decl(file1.ts, 1, 38))
export const elem: HTMLElement = { field: 'a' };
>elem : Symbol(elem, Decl(file1.ts, 2, 12))
>HTMLElement : Symbol(HTMLElement, Decl(file1.ts, 0, 0))
>field : Symbol(field, Decl(file1.ts, 2, 34))

View File

@ -0,0 +1,24 @@
=== tests/cases/conformance/declarationEmit/fakelib.ts ===
// Test that passing noLib disables <reference lib> resolution.
No type information for this code.
No type information for this code.interface Object { }
No type information for this code.interface Array<T> { }
No type information for this code.interface String { }
No type information for this code.interface Boolean { }
No type information for this code.interface Number { }
No type information for this code.interface Function { }
No type information for this code.interface RegExp { }
No type information for this code.interface IArguments { }
No type information for this code.
No type information for this code.
No type information for this code.=== tests/cases/conformance/declarationEmit/file1.ts ===
/// <reference lib="dom" />
export declare interface HTMLElement { field: string; }
>field : string
export const elem: HTMLElement = { field: 'a' };
>elem : HTMLElement
>{ field: 'a' } : { field: string; }
>field : string
>'a' : "a"

View File

@ -0,0 +1,21 @@
// @target: esnext
// @module: commonjs
// @noLib: true
// @declaration: true
// Test that passing noLib disables <reference lib> resolution.
// @filename: fakelib.ts
interface Object { }
interface Array<T> { }
interface String { }
interface Boolean { }
interface Number { }
interface Function { }
interface RegExp { }
interface IArguments { }
// @filename: file1.ts
/// <reference lib="dom" />
export declare interface HTMLElement { field: string; }
export const elem: HTMLElement = { field: 'a' };

View File

@ -0,0 +1,23 @@
// @target: esnext
// @module: amd
// @noLib: true
// @declaration: true
// @outFile: bundle.js
// Test that passing noLib disables <reference lib> resolution.
// @filename: fakelib.ts
interface Object { }
interface Array<T> { }
interface String { }
interface Boolean { }
interface Number { }
interface Function { }
interface RegExp { }
interface IArguments { }
// @filename: file1.ts
/// <reference lib="dom" />
export declare interface HTMLElement { field: string; }
export const elem: HTMLElement = { field: 'a' };

View File

@ -0,0 +1,26 @@
/// <reference path='fourslash.ts' />
// @Filename: /dir/a.ts
////declare const decorator: any;
////class A {
//// @decorator method() {};
////};
// @Filename: /dir/tsconfig.json
////{
//// "compilerOptions": {
//// }
////}
goTo.file("/dir/a.ts");
verify.codeFix({
description: "Enable the 'experimentalDecorators' option in your configuration file",
newFileContent: {
"/dir/tsconfig.json":
`{
"compilerOptions": {
"experimentalDecorators": true,
}
}`,
},
});

View File

@ -0,0 +1,27 @@
/// <reference path='fourslash.ts' />
// @Filename: /dir/a.ts
////declare const decorator: any;
////class A {
//// @decorator method() {};
////};
// @Filename: /dir/tsconfig.json
////{
//// "compilerOptions": {
//// "experimentalDecorators": false,
//// }
////}
goTo.file("/dir/a.ts");
verify.codeFix({
description: "Enable the 'experimentalDecorators' option in your configuration file",
newFileContent: {
"/dir/tsconfig.json":
`{
"compilerOptions": {
"experimentalDecorators": true,
}
}`,
},
});

View File

@ -0,0 +1,22 @@
/// <reference path='fourslash.ts' />
// @Filename: /dir/a.ts
////declare const decorator: any;
////class A {
//// @decorator method() {};
////};
// @Filename: /dir/tsconfig.json
////{
////}
goTo.file("/dir/a.ts");
verify.codeFix({
description: "Enable the 'experimentalDecorators' option in your configuration file",
newFileContent: {
"/dir/tsconfig.json":
`{
"compilerOptions": { "experimentalDecorators": true },
}`,
},
});

View File

@ -0,0 +1,10 @@
/// <reference path='fourslash.ts' />
// @Filename: /dir/a.ts
////declare const decorator: any;
////class A {
//// @decorator method() {};
////};
goTo.file("/dir/a.ts");
verify.not.codeFixAvailable();