mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge branch 'emitHelper' into asyncGenerators
This commit is contained in:
+4
-3
@@ -128,7 +128,8 @@ const es2016LibrarySourceMap = es2016LibrarySource.map(function(source) {
|
||||
|
||||
const es2017LibrarySource = [
|
||||
"es2017.object.d.ts",
|
||||
"es2017.sharedmemory.d.ts"
|
||||
"es2017.sharedmemory.d.ts",
|
||||
"es2017.string.d.ts",
|
||||
];
|
||||
|
||||
const es2017LibrarySourceMap = es2017LibrarySource.map(function(source) {
|
||||
@@ -176,7 +177,7 @@ for (const i in libraryTargets) {
|
||||
const configureNightlyJs = path.join(scriptsDirectory, "configureNightly.js");
|
||||
const configureNightlyTs = path.join(scriptsDirectory, "configureNightly.ts");
|
||||
const packageJson = "package.json";
|
||||
const programTs = path.join(compilerDirectory, "program.ts");
|
||||
const versionFile = path.join(compilerDirectory, "core.ts");
|
||||
|
||||
function needsUpdate(source: string | string[], dest: string | string[]): boolean {
|
||||
if (typeof source === "string" && typeof dest === "string") {
|
||||
@@ -284,7 +285,7 @@ gulp.task(configureNightlyJs, false, [], () => {
|
||||
|
||||
// Nightly management tasks
|
||||
gulp.task("configure-nightly", "Runs scripts/configureNightly.ts to prepare a build for nightly publishing", [configureNightlyJs], (done) => {
|
||||
exec(host, [configureNightlyJs, packageJson, programTs], done, done);
|
||||
exec(host, [configureNightlyJs, packageJson, versionFile], done, done);
|
||||
});
|
||||
gulp.task("publish-nightly", "Runs `npm publish --tag next` to create a new nightly build on npm", ["LKG"], () => {
|
||||
return runSequence("clean", "useDebugMode", "runtests", (done) => {
|
||||
|
||||
+7
-4
@@ -71,6 +71,7 @@ var compilerSources = [
|
||||
"transformers/destructuring.ts",
|
||||
"transformers/ts.ts",
|
||||
"transformers/jsx.ts",
|
||||
"transformers/esnext.ts",
|
||||
"transformers/es2017.ts",
|
||||
"transformers/es2016.ts",
|
||||
"transformers/es2015.ts",
|
||||
@@ -107,6 +108,7 @@ var servicesSources = [
|
||||
"transformers/destructuring.ts",
|
||||
"transformers/ts.ts",
|
||||
"transformers/jsx.ts",
|
||||
"transformers/esnext.ts",
|
||||
"transformers/es2017.ts",
|
||||
"transformers/es2016.ts",
|
||||
"transformers/es2015.ts",
|
||||
@@ -301,7 +303,8 @@ var es2016LibrarySourceMap = es2016LibrarySource.map(function (source) {
|
||||
|
||||
var es2017LibrarySource = [
|
||||
"es2017.object.d.ts",
|
||||
"es2017.sharedmemory.d.ts"
|
||||
"es2017.sharedmemory.d.ts",
|
||||
"es2017.string.d.ts",
|
||||
];
|
||||
|
||||
var es2017LibrarySourceMap = es2017LibrarySource.map(function (source) {
|
||||
@@ -590,7 +593,7 @@ task("generate-diagnostics", [diagnosticInfoMapTs]);
|
||||
var configureNightlyJs = path.join(scriptsDirectory, "configureNightly.js");
|
||||
var configureNightlyTs = path.join(scriptsDirectory, "configureNightly.ts");
|
||||
var packageJson = "package.json";
|
||||
var programTs = path.join(compilerDirectory, "program.ts");
|
||||
var versionFile = path.join(compilerDirectory, "core.ts");
|
||||
|
||||
file(configureNightlyTs);
|
||||
|
||||
@@ -606,7 +609,7 @@ task("setDebugMode", function () {
|
||||
});
|
||||
|
||||
task("configure-nightly", [configureNightlyJs], function () {
|
||||
var cmd = host + " " + configureNightlyJs + " " + packageJson + " " + programTs;
|
||||
var cmd = host + " " + configureNightlyJs + " " + packageJson + " " + versionFile;
|
||||
console.log(cmd);
|
||||
exec(cmd);
|
||||
}, { async: true });
|
||||
@@ -637,7 +640,7 @@ task("importDefinitelyTypedTests", [importDefinitelyTypedTestsJs], function () {
|
||||
|
||||
// Local target to build the compiler and services
|
||||
var tscFile = path.join(builtLocalDirectory, compilerFilename);
|
||||
compileFile(tscFile, compilerSources, [builtLocalDirectory, copyright].concat(compilerSources), [copyright], /*useBuiltCompiler:*/ false);
|
||||
compileFile(tscFile, compilerSources, [builtLocalDirectory, copyright].concat(compilerSources), [copyright], /*useBuiltCompiler:*/ false, { noMapRoot: true });
|
||||
|
||||
var servicesFile = path.join(builtLocalDirectory, "typescriptServices.js");
|
||||
var servicesFileInBrowserTest = path.join(builtLocalDirectory, "typescriptServicesInBrowserTest.js");
|
||||
|
||||
@@ -39,5 +39,3 @@ function createCancellationToken(args) {
|
||||
};
|
||||
}
|
||||
module.exports = createCancellationToken;
|
||||
|
||||
//# sourceMappingURL=cancellationToken.js.map
|
||||
|
||||
Vendored
+14
-10
@@ -5836,6 +5836,7 @@ interface CSSStyleDeclaration {
|
||||
writingMode: string | null;
|
||||
zIndex: string | null;
|
||||
zoom: string | null;
|
||||
resize: string | null;
|
||||
getPropertyPriority(propertyName: string): string;
|
||||
getPropertyValue(propertyName: string): string;
|
||||
item(index: number): string;
|
||||
@@ -5905,6 +5906,7 @@ declare var CanvasGradient: {
|
||||
}
|
||||
|
||||
interface CanvasPattern {
|
||||
setTransform(matrix: SVGMatrix): void;
|
||||
}
|
||||
|
||||
declare var CanvasPattern: {
|
||||
@@ -6330,7 +6332,7 @@ interface DataTransfer {
|
||||
effectAllowed: string;
|
||||
readonly files: FileList;
|
||||
readonly items: DataTransferItemList;
|
||||
readonly types: DOMStringList;
|
||||
readonly types: string[];
|
||||
clearData(format?: string): boolean;
|
||||
getData(format: string): string;
|
||||
setData(format: string, data: string): boolean;
|
||||
@@ -12759,7 +12761,7 @@ interface MouseEvent extends UIEvent {
|
||||
readonly x: number;
|
||||
readonly y: number;
|
||||
getModifierState(keyArg: string): boolean;
|
||||
initMouseEvent(typeArg: string, canBubbleArg: boolean, cancelableArg: boolean, viewArg: Window, detailArg: number, screenXArg: number, screenYArg: number, clientXArg: number, clientYArg: number, ctrlKeyArg: boolean, altKeyArg: boolean, shiftKeyArg: boolean, metaKeyArg: boolean, buttonArg: number, relatedTargetArg: EventTarget): void;
|
||||
initMouseEvent(typeArg: string, canBubbleArg: boolean, cancelableArg: boolean, viewArg: Window, detailArg: number, screenXArg: number, screenYArg: number, clientXArg: number, clientYArg: number, ctrlKeyArg: boolean, altKeyArg: boolean, shiftKeyArg: boolean, metaKeyArg: boolean, buttonArg: number, relatedTargetArg: EventTarget | null): void;
|
||||
}
|
||||
|
||||
declare var MouseEvent: {
|
||||
@@ -12872,6 +12874,7 @@ interface Navigator extends Object, NavigatorID, NavigatorOnLine, NavigatorConte
|
||||
readonly plugins: PluginArray;
|
||||
readonly pointerEnabled: boolean;
|
||||
readonly webdriver: boolean;
|
||||
readonly hardwareConcurrency: number;
|
||||
getGamepads(): Gamepad[];
|
||||
javaEnabled(): boolean;
|
||||
msLaunchUri(uri: string, successCallback?: MSLaunchUriCallback, noHandlerCallback?: MSLaunchUriCallback): void;
|
||||
@@ -12889,18 +12892,18 @@ interface Node extends EventTarget {
|
||||
readonly attributes: NamedNodeMap;
|
||||
readonly baseURI: string | null;
|
||||
readonly childNodes: NodeList;
|
||||
readonly firstChild: Node;
|
||||
readonly lastChild: Node;
|
||||
readonly firstChild: Node | null;
|
||||
readonly lastChild: Node | null;
|
||||
readonly localName: string | null;
|
||||
readonly namespaceURI: string | null;
|
||||
readonly nextSibling: Node;
|
||||
readonly nextSibling: Node | null;
|
||||
readonly nodeName: string;
|
||||
readonly nodeType: number;
|
||||
nodeValue: string | null;
|
||||
readonly ownerDocument: Document;
|
||||
readonly parentElement: HTMLElement;
|
||||
readonly parentNode: Node;
|
||||
readonly previousSibling: Node;
|
||||
readonly parentElement: HTMLElement | null;
|
||||
readonly parentNode: Node | null;
|
||||
readonly previousSibling: Node | null;
|
||||
textContent: string | null;
|
||||
appendChild(newChild: Node): Node;
|
||||
cloneNode(deep?: boolean): Node;
|
||||
@@ -17010,7 +17013,7 @@ interface Window extends EventTarget, WindowTimers, WindowSessionStorage, Window
|
||||
readonly devicePixelRatio: number;
|
||||
readonly doNotTrack: string;
|
||||
readonly document: Document;
|
||||
event: Event;
|
||||
event: Event | undefined;
|
||||
readonly external: External;
|
||||
readonly frameElement: Element;
|
||||
readonly frames: Window;
|
||||
@@ -17312,6 +17315,7 @@ interface XMLHttpRequest extends EventTarget, XMLHttpRequestEventTarget {
|
||||
readonly upload: XMLHttpRequestUpload;
|
||||
withCredentials: boolean;
|
||||
msCaching?: string;
|
||||
readonly responseURL: string;
|
||||
abort(): void;
|
||||
getAllResponseHeaders(): string;
|
||||
getResponseHeader(header: string): string | null;
|
||||
@@ -18458,7 +18462,7 @@ declare var defaultStatus: string;
|
||||
declare var devicePixelRatio: number;
|
||||
declare var doNotTrack: string;
|
||||
declare var document: Document;
|
||||
declare var event: Event;
|
||||
declare var event: Event | undefined;
|
||||
declare var external: External;
|
||||
declare var frameElement: Element;
|
||||
declare var frames: Window;
|
||||
|
||||
Vendored
+14
-10
@@ -1699,6 +1699,7 @@ interface CSSStyleDeclaration {
|
||||
writingMode: string | null;
|
||||
zIndex: string | null;
|
||||
zoom: string | null;
|
||||
resize: string | null;
|
||||
getPropertyPriority(propertyName: string): string;
|
||||
getPropertyValue(propertyName: string): string;
|
||||
item(index: number): string;
|
||||
@@ -1768,6 +1769,7 @@ declare var CanvasGradient: {
|
||||
}
|
||||
|
||||
interface CanvasPattern {
|
||||
setTransform(matrix: SVGMatrix): void;
|
||||
}
|
||||
|
||||
declare var CanvasPattern: {
|
||||
@@ -2193,7 +2195,7 @@ interface DataTransfer {
|
||||
effectAllowed: string;
|
||||
readonly files: FileList;
|
||||
readonly items: DataTransferItemList;
|
||||
readonly types: DOMStringList;
|
||||
readonly types: string[];
|
||||
clearData(format?: string): boolean;
|
||||
getData(format: string): string;
|
||||
setData(format: string, data: string): boolean;
|
||||
@@ -8622,7 +8624,7 @@ interface MouseEvent extends UIEvent {
|
||||
readonly x: number;
|
||||
readonly y: number;
|
||||
getModifierState(keyArg: string): boolean;
|
||||
initMouseEvent(typeArg: string, canBubbleArg: boolean, cancelableArg: boolean, viewArg: Window, detailArg: number, screenXArg: number, screenYArg: number, clientXArg: number, clientYArg: number, ctrlKeyArg: boolean, altKeyArg: boolean, shiftKeyArg: boolean, metaKeyArg: boolean, buttonArg: number, relatedTargetArg: EventTarget): void;
|
||||
initMouseEvent(typeArg: string, canBubbleArg: boolean, cancelableArg: boolean, viewArg: Window, detailArg: number, screenXArg: number, screenYArg: number, clientXArg: number, clientYArg: number, ctrlKeyArg: boolean, altKeyArg: boolean, shiftKeyArg: boolean, metaKeyArg: boolean, buttonArg: number, relatedTargetArg: EventTarget | null): void;
|
||||
}
|
||||
|
||||
declare var MouseEvent: {
|
||||
@@ -8735,6 +8737,7 @@ interface Navigator extends Object, NavigatorID, NavigatorOnLine, NavigatorConte
|
||||
readonly plugins: PluginArray;
|
||||
readonly pointerEnabled: boolean;
|
||||
readonly webdriver: boolean;
|
||||
readonly hardwareConcurrency: number;
|
||||
getGamepads(): Gamepad[];
|
||||
javaEnabled(): boolean;
|
||||
msLaunchUri(uri: string, successCallback?: MSLaunchUriCallback, noHandlerCallback?: MSLaunchUriCallback): void;
|
||||
@@ -8752,18 +8755,18 @@ interface Node extends EventTarget {
|
||||
readonly attributes: NamedNodeMap;
|
||||
readonly baseURI: string | null;
|
||||
readonly childNodes: NodeList;
|
||||
readonly firstChild: Node;
|
||||
readonly lastChild: Node;
|
||||
readonly firstChild: Node | null;
|
||||
readonly lastChild: Node | null;
|
||||
readonly localName: string | null;
|
||||
readonly namespaceURI: string | null;
|
||||
readonly nextSibling: Node;
|
||||
readonly nextSibling: Node | null;
|
||||
readonly nodeName: string;
|
||||
readonly nodeType: number;
|
||||
nodeValue: string | null;
|
||||
readonly ownerDocument: Document;
|
||||
readonly parentElement: HTMLElement;
|
||||
readonly parentNode: Node;
|
||||
readonly previousSibling: Node;
|
||||
readonly parentElement: HTMLElement | null;
|
||||
readonly parentNode: Node | null;
|
||||
readonly previousSibling: Node | null;
|
||||
textContent: string | null;
|
||||
appendChild(newChild: Node): Node;
|
||||
cloneNode(deep?: boolean): Node;
|
||||
@@ -12873,7 +12876,7 @@ interface Window extends EventTarget, WindowTimers, WindowSessionStorage, Window
|
||||
readonly devicePixelRatio: number;
|
||||
readonly doNotTrack: string;
|
||||
readonly document: Document;
|
||||
event: Event;
|
||||
event: Event | undefined;
|
||||
readonly external: External;
|
||||
readonly frameElement: Element;
|
||||
readonly frames: Window;
|
||||
@@ -13175,6 +13178,7 @@ interface XMLHttpRequest extends EventTarget, XMLHttpRequestEventTarget {
|
||||
readonly upload: XMLHttpRequestUpload;
|
||||
withCredentials: boolean;
|
||||
msCaching?: string;
|
||||
readonly responseURL: string;
|
||||
abort(): void;
|
||||
getAllResponseHeaders(): string;
|
||||
getResponseHeader(header: string): string | null;
|
||||
@@ -14321,7 +14325,7 @@ declare var defaultStatus: string;
|
||||
declare var devicePixelRatio: number;
|
||||
declare var doNotTrack: string;
|
||||
declare var document: Document;
|
||||
declare var event: Event;
|
||||
declare var event: Event | undefined;
|
||||
declare var external: External;
|
||||
declare var frameElement: Element;
|
||||
declare var frames: Window;
|
||||
|
||||
Vendored
+4
-4
@@ -225,13 +225,13 @@ interface NumberConstructor {
|
||||
* number. Only finite values of the type number, result in true.
|
||||
* @param number A numeric value.
|
||||
*/
|
||||
isFinite(number: number): boolean;
|
||||
isFinite(value: any): value is number;
|
||||
|
||||
/**
|
||||
* Returns true if the value passed is an integer, false otherwise.
|
||||
* @param number A numeric value.
|
||||
*/
|
||||
isInteger(number: number): boolean;
|
||||
isInteger(value: any): value is number;
|
||||
|
||||
/**
|
||||
* Returns a Boolean value that indicates whether a value is the reserved value NaN (not a
|
||||
@@ -239,13 +239,13 @@ interface NumberConstructor {
|
||||
* to a number. Only values of the type number, that are also NaN, result in true.
|
||||
* @param number A numeric value.
|
||||
*/
|
||||
isNaN(number: number): boolean;
|
||||
isNaN(value: any): value is number;
|
||||
|
||||
/**
|
||||
* Returns true if the value passed is a safe integer.
|
||||
* @param number A numeric value.
|
||||
*/
|
||||
isSafeInteger(number: number): boolean;
|
||||
isSafeInteger(value: any): value is number;
|
||||
|
||||
/**
|
||||
* The value of the largest integer n such that n and n + 1 are both exactly representable as
|
||||
|
||||
Vendored
+3
-3
@@ -19,7 +19,7 @@ and limitations under the License.
|
||||
|
||||
|
||||
interface ProxyHandler<T> {
|
||||
getPrototypeOf? (target: T): any;
|
||||
getPrototypeOf? (target: T): {} | null;
|
||||
setPrototypeOf? (target: T, v: any): boolean;
|
||||
isExtensible? (target: T): boolean;
|
||||
preventExtensions? (target: T): boolean;
|
||||
@@ -32,11 +32,11 @@ interface ProxyHandler<T> {
|
||||
enumerate? (target: T): PropertyKey[];
|
||||
ownKeys? (target: T): PropertyKey[];
|
||||
apply? (target: T, thisArg: any, argArray?: any): any;
|
||||
construct? (target: T, thisArg: any, argArray?: any): any;
|
||||
construct? (target: T, argArray: any, newTarget?: any): {};
|
||||
}
|
||||
|
||||
interface ProxyConstructor {
|
||||
revocable<T>(target: T, handler: ProxyHandler<T>): { proxy: T; revoke: () => void; };
|
||||
new <T>(target: T, handler: ProxyHandler<T>): T
|
||||
}
|
||||
declare var Proxy: ProxyConstructor;
|
||||
declare var Proxy: ProxyConstructor;
|
||||
|
||||
Vendored
+2
-1
@@ -20,4 +20,5 @@ and limitations under the License.
|
||||
|
||||
/// <reference path="lib.es2016.d.ts" />
|
||||
/// <reference path="lib.es2017.object.d.ts" />
|
||||
/// <reference path="lib.es2017.sharedmemory.d.ts" />
|
||||
/// <reference path="lib.es2017.sharedmemory.d.ts" />
|
||||
/// <reference path="lib.es2017.string.d.ts" />
|
||||
|
||||
Vendored
+2
-2
@@ -29,6 +29,6 @@ interface ObjectConstructor {
|
||||
* Returns an array of key/values of the enumerable properties of an object
|
||||
* @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
|
||||
*/
|
||||
entries<T>(o: { [s: string]: T }): [string, T][];
|
||||
entries<T extends { [key: string]: any }, K extends keyof T>(o: T): [keyof T, T[K]][];
|
||||
entries(o: any): [string, any][];
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+47
@@ -0,0 +1,47 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABLITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
|
||||
/// <reference no-default-lib="true"/>
|
||||
|
||||
|
||||
interface String {
|
||||
/**
|
||||
* Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length.
|
||||
* The padding is applied from the start (left) of the current string.
|
||||
*
|
||||
* @param maxLength The length of the resulting string once the current string has been padded.
|
||||
* If this parameter is smaller than the current string's length, the current string will be returned as it is.
|
||||
*
|
||||
* @param fillString The string to pad the current string with.
|
||||
* If this string is too long, it will be truncated and the left-most part will be applied.
|
||||
* The default value for this parameter is " " (U+0020).
|
||||
*/
|
||||
padStart(maxLength: number, fillString?: string): string;
|
||||
|
||||
/**
|
||||
* Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length.
|
||||
* The padding is applied from the end (right) of the current string.
|
||||
*
|
||||
* @param maxLength The length of the resulting string once the current string has been padded.
|
||||
* If this parameter is smaller than the current string's length, the current string will be returned as it is.
|
||||
*
|
||||
* @param fillString The string to pad the current string with.
|
||||
* If this string is too long, it will be truncated and the left-most part will be applied.
|
||||
* The default value for this parameter is " " (U+0020).
|
||||
*/
|
||||
padEnd(maxLength: number, fillString?: string): string;
|
||||
}
|
||||
Vendored
+22
-17
@@ -4362,13 +4362,13 @@ interface NumberConstructor {
|
||||
* number. Only finite values of the type number, result in true.
|
||||
* @param number A numeric value.
|
||||
*/
|
||||
isFinite(number: number): boolean;
|
||||
isFinite(value: any): value is number;
|
||||
|
||||
/**
|
||||
* Returns true if the value passed is an integer, false otherwise.
|
||||
* @param number A numeric value.
|
||||
*/
|
||||
isInteger(number: number): boolean;
|
||||
isInteger(value: any): value is number;
|
||||
|
||||
/**
|
||||
* Returns a Boolean value that indicates whether a value is the reserved value NaN (not a
|
||||
@@ -4376,13 +4376,13 @@ interface NumberConstructor {
|
||||
* to a number. Only values of the type number, that are also NaN, result in true.
|
||||
* @param number A numeric value.
|
||||
*/
|
||||
isNaN(number: number): boolean;
|
||||
isNaN(value: any): value is number;
|
||||
|
||||
/**
|
||||
* Returns true if the value passed is a safe integer.
|
||||
* @param number A numeric value.
|
||||
*/
|
||||
isSafeInteger(number: number): boolean;
|
||||
isSafeInteger(value: any): value is number;
|
||||
|
||||
/**
|
||||
* The value of the largest integer n such that n and n + 1 are both exactly representable as
|
||||
@@ -5471,7 +5471,7 @@ interface PromiseConstructor {
|
||||
declare var Promise: PromiseConstructor;
|
||||
|
||||
interface ProxyHandler<T> {
|
||||
getPrototypeOf? (target: T): any;
|
||||
getPrototypeOf? (target: T): {} | null;
|
||||
setPrototypeOf? (target: T, v: any): boolean;
|
||||
isExtensible? (target: T): boolean;
|
||||
preventExtensions? (target: T): boolean;
|
||||
@@ -5484,14 +5484,15 @@ interface ProxyHandler<T> {
|
||||
enumerate? (target: T): PropertyKey[];
|
||||
ownKeys? (target: T): PropertyKey[];
|
||||
apply? (target: T, thisArg: any, argArray?: any): any;
|
||||
construct? (target: T, thisArg: any, argArray?: any): any;
|
||||
construct? (target: T, argArray: any, newTarget?: any): {};
|
||||
}
|
||||
|
||||
interface ProxyConstructor {
|
||||
revocable<T>(target: T, handler: ProxyHandler<T>): { proxy: T; revoke: () => void; };
|
||||
new <T>(target: T, handler: ProxyHandler<T>): T
|
||||
}
|
||||
declare var Proxy: ProxyConstructor;
|
||||
declare var Proxy: ProxyConstructor;
|
||||
|
||||
|
||||
declare namespace Reflect {
|
||||
function apply(target: Function, thisArgument: any, argumentsList: ArrayLike<any>): any;
|
||||
@@ -7555,6 +7556,7 @@ interface CSSStyleDeclaration {
|
||||
writingMode: string | null;
|
||||
zIndex: string | null;
|
||||
zoom: string | null;
|
||||
resize: string | null;
|
||||
getPropertyPriority(propertyName: string): string;
|
||||
getPropertyValue(propertyName: string): string;
|
||||
item(index: number): string;
|
||||
@@ -7624,6 +7626,7 @@ declare var CanvasGradient: {
|
||||
}
|
||||
|
||||
interface CanvasPattern {
|
||||
setTransform(matrix: SVGMatrix): void;
|
||||
}
|
||||
|
||||
declare var CanvasPattern: {
|
||||
@@ -8049,7 +8052,7 @@ interface DataTransfer {
|
||||
effectAllowed: string;
|
||||
readonly files: FileList;
|
||||
readonly items: DataTransferItemList;
|
||||
readonly types: DOMStringList;
|
||||
readonly types: string[];
|
||||
clearData(format?: string): boolean;
|
||||
getData(format: string): string;
|
||||
setData(format: string, data: string): boolean;
|
||||
@@ -14478,7 +14481,7 @@ interface MouseEvent extends UIEvent {
|
||||
readonly x: number;
|
||||
readonly y: number;
|
||||
getModifierState(keyArg: string): boolean;
|
||||
initMouseEvent(typeArg: string, canBubbleArg: boolean, cancelableArg: boolean, viewArg: Window, detailArg: number, screenXArg: number, screenYArg: number, clientXArg: number, clientYArg: number, ctrlKeyArg: boolean, altKeyArg: boolean, shiftKeyArg: boolean, metaKeyArg: boolean, buttonArg: number, relatedTargetArg: EventTarget): void;
|
||||
initMouseEvent(typeArg: string, canBubbleArg: boolean, cancelableArg: boolean, viewArg: Window, detailArg: number, screenXArg: number, screenYArg: number, clientXArg: number, clientYArg: number, ctrlKeyArg: boolean, altKeyArg: boolean, shiftKeyArg: boolean, metaKeyArg: boolean, buttonArg: number, relatedTargetArg: EventTarget | null): void;
|
||||
}
|
||||
|
||||
declare var MouseEvent: {
|
||||
@@ -14591,6 +14594,7 @@ interface Navigator extends Object, NavigatorID, NavigatorOnLine, NavigatorConte
|
||||
readonly plugins: PluginArray;
|
||||
readonly pointerEnabled: boolean;
|
||||
readonly webdriver: boolean;
|
||||
readonly hardwareConcurrency: number;
|
||||
getGamepads(): Gamepad[];
|
||||
javaEnabled(): boolean;
|
||||
msLaunchUri(uri: string, successCallback?: MSLaunchUriCallback, noHandlerCallback?: MSLaunchUriCallback): void;
|
||||
@@ -14608,18 +14612,18 @@ interface Node extends EventTarget {
|
||||
readonly attributes: NamedNodeMap;
|
||||
readonly baseURI: string | null;
|
||||
readonly childNodes: NodeList;
|
||||
readonly firstChild: Node;
|
||||
readonly lastChild: Node;
|
||||
readonly firstChild: Node | null;
|
||||
readonly lastChild: Node | null;
|
||||
readonly localName: string | null;
|
||||
readonly namespaceURI: string | null;
|
||||
readonly nextSibling: Node;
|
||||
readonly nextSibling: Node | null;
|
||||
readonly nodeName: string;
|
||||
readonly nodeType: number;
|
||||
nodeValue: string | null;
|
||||
readonly ownerDocument: Document;
|
||||
readonly parentElement: HTMLElement;
|
||||
readonly parentNode: Node;
|
||||
readonly previousSibling: Node;
|
||||
readonly parentElement: HTMLElement | null;
|
||||
readonly parentNode: Node | null;
|
||||
readonly previousSibling: Node | null;
|
||||
textContent: string | null;
|
||||
appendChild(newChild: Node): Node;
|
||||
cloneNode(deep?: boolean): Node;
|
||||
@@ -18729,7 +18733,7 @@ interface Window extends EventTarget, WindowTimers, WindowSessionStorage, Window
|
||||
readonly devicePixelRatio: number;
|
||||
readonly doNotTrack: string;
|
||||
readonly document: Document;
|
||||
event: Event;
|
||||
event: Event | undefined;
|
||||
readonly external: External;
|
||||
readonly frameElement: Element;
|
||||
readonly frames: Window;
|
||||
@@ -19031,6 +19035,7 @@ interface XMLHttpRequest extends EventTarget, XMLHttpRequestEventTarget {
|
||||
readonly upload: XMLHttpRequestUpload;
|
||||
withCredentials: boolean;
|
||||
msCaching?: string;
|
||||
readonly responseURL: string;
|
||||
abort(): void;
|
||||
getAllResponseHeaders(): string;
|
||||
getResponseHeader(header: string): string | null;
|
||||
@@ -20177,7 +20182,7 @@ declare var defaultStatus: string;
|
||||
declare var devicePixelRatio: number;
|
||||
declare var doNotTrack: string;
|
||||
declare var document: Document;
|
||||
declare var event: Event;
|
||||
declare var event: Event | undefined;
|
||||
declare var external: External;
|
||||
declare var frameElement: Element;
|
||||
declare var frames: Window;
|
||||
|
||||
Vendored
+2
@@ -760,6 +760,7 @@ interface XMLHttpRequest extends EventTarget, XMLHttpRequestEventTarget {
|
||||
readonly upload: XMLHttpRequestUpload;
|
||||
withCredentials: boolean;
|
||||
msCaching?: string;
|
||||
readonly responseURL: string;
|
||||
abort(): void;
|
||||
getAllResponseHeaders(): string;
|
||||
getResponseHeader(header: string): string | null;
|
||||
@@ -922,6 +923,7 @@ declare var WorkerLocation: {
|
||||
}
|
||||
|
||||
interface WorkerNavigator extends Object, NavigatorID, NavigatorOnLine {
|
||||
readonly hardwareConcurrency: number;
|
||||
addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;
|
||||
}
|
||||
|
||||
|
||||
Vendored
+168
-205
@@ -59,7 +59,7 @@ declare namespace ts.server.protocol {
|
||||
/**
|
||||
* One of "request", "response", or "event"
|
||||
*/
|
||||
type: string;
|
||||
type: "request" | "response" | "event";
|
||||
}
|
||||
/**
|
||||
* Client-initiated request message
|
||||
@@ -653,7 +653,7 @@ declare namespace ts.server.protocol {
|
||||
/**
|
||||
* Script kind of the file
|
||||
*/
|
||||
scriptKind?: ScriptKind;
|
||||
scriptKind?: ScriptKindName | ts.ScriptKind;
|
||||
/**
|
||||
* Whether file has mixed content (i.e. .cshtml file that combines html markup with C#/JavaScript)
|
||||
*/
|
||||
@@ -684,37 +684,17 @@ declare namespace ts.server.protocol {
|
||||
*/
|
||||
typingOptions?: TypingOptions;
|
||||
}
|
||||
/**
|
||||
* For external projects, some of the project settings are sent together with
|
||||
* compiler settings.
|
||||
*/
|
||||
interface ExternalProjectCompilerOptions extends CompilerOptions {
|
||||
interface CompileOnSaveMixin {
|
||||
/**
|
||||
* If compile on save is enabled for the project
|
||||
*/
|
||||
compileOnSave?: boolean;
|
||||
}
|
||||
/**
|
||||
* Contains information about current project version
|
||||
* For external projects, some of the project settings are sent together with
|
||||
* compiler settings.
|
||||
*/
|
||||
interface ProjectVersionInfo {
|
||||
/**
|
||||
* Project name
|
||||
*/
|
||||
projectName: string;
|
||||
/**
|
||||
* true if project is inferred or false if project is external or configured
|
||||
*/
|
||||
isInferred: boolean;
|
||||
/**
|
||||
* Project version
|
||||
*/
|
||||
version: number;
|
||||
/**
|
||||
* Current set of compiler options for project
|
||||
*/
|
||||
options: CompilerOptions;
|
||||
}
|
||||
type ExternalProjectCompilerOptions = CompilerOptions & CompileOnSaveMixin;
|
||||
/**
|
||||
* Represents a set of changes that happen in project
|
||||
*/
|
||||
@@ -728,36 +708,6 @@ declare namespace ts.server.protocol {
|
||||
*/
|
||||
removed: string[];
|
||||
}
|
||||
/**
|
||||
* Describes set of files in the project.
|
||||
* info might be omitted in case of inferred projects
|
||||
* if files is set - then this is the entire set of files in the project
|
||||
* if changes is set - then this is the set of changes that should be applied to existing project
|
||||
* otherwise - assume that nothing is changed
|
||||
*/
|
||||
interface ProjectFiles {
|
||||
/**
|
||||
* Information abount project verison
|
||||
*/
|
||||
info?: ProjectVersionInfo;
|
||||
/**
|
||||
* List of files in project (might be omitted if current state of project can be computed using only information from 'changes')
|
||||
*/
|
||||
files?: string[];
|
||||
/**
|
||||
* Set of changes in project (omitted if the entire set of files in project should be replaced)
|
||||
*/
|
||||
changes?: ProjectChanges;
|
||||
}
|
||||
/**
|
||||
* Combines project information with project level errors.
|
||||
*/
|
||||
interface ProjectFilesWithDiagnostics extends ProjectFiles {
|
||||
/**
|
||||
* List of errors in project
|
||||
*/
|
||||
projectErrors: DiagnosticWithLinePosition[];
|
||||
}
|
||||
/**
|
||||
* Information found in a configure request.
|
||||
*/
|
||||
@@ -803,8 +753,9 @@ declare namespace ts.server.protocol {
|
||||
* Used to specify the script kind of the file explicitly. It could be one of the following:
|
||||
* "TS", "JS", "TSX", "JSX"
|
||||
*/
|
||||
scriptKindName?: "TS" | "JS" | "TSX" | "JSX";
|
||||
scriptKindName?: ScriptKindName;
|
||||
}
|
||||
type ScriptKindName = "TS" | "JS" | "TSX" | "JSX";
|
||||
/**
|
||||
* Open request; value of command field is "open". Notify the
|
||||
* server that the client has file open. The server will not
|
||||
@@ -878,15 +829,6 @@ declare namespace ts.server.protocol {
|
||||
*/
|
||||
interface CloseExternalProjectResponse extends Response {
|
||||
}
|
||||
/**
|
||||
* Arguments to SynchronizeProjectListRequest
|
||||
*/
|
||||
interface SynchronizeProjectListRequestArgs {
|
||||
/**
|
||||
* List of last known projects
|
||||
*/
|
||||
knownProjects: protocol.ProjectVersionInfo[];
|
||||
}
|
||||
/**
|
||||
* Request to set compiler options for inferred projects.
|
||||
* External projects are opened / closed explicitly.
|
||||
@@ -1669,12 +1611,158 @@ declare namespace ts.server.protocol {
|
||||
spans: TextSpan[];
|
||||
childItems?: NavigationTree[];
|
||||
}
|
||||
type TelemetryEventName = "telemetry";
|
||||
interface TelemetryEvent extends Event {
|
||||
event: TelemetryEventName;
|
||||
body: TelemetryEventBody;
|
||||
}
|
||||
interface TelemetryEventBody {
|
||||
telemetryEventName: string;
|
||||
payload: any;
|
||||
}
|
||||
type TypingsInstalledTelemetryEventName = "typingsInstalled";
|
||||
interface TypingsInstalledTelemetryEventBody extends TelemetryEventBody {
|
||||
telemetryEventName: TypingsInstalledTelemetryEventName;
|
||||
payload: TypingsInstalledTelemetryEventPayload;
|
||||
}
|
||||
interface TypingsInstalledTelemetryEventPayload {
|
||||
/**
|
||||
* Comma separated list of installed typing packages
|
||||
*/
|
||||
installedPackages: string;
|
||||
/**
|
||||
* true if install request succeeded, otherwise - false
|
||||
*/
|
||||
installSuccess: boolean;
|
||||
}
|
||||
interface NavBarResponse extends Response {
|
||||
body?: NavigationBarItem[];
|
||||
}
|
||||
interface NavTreeResponse extends Response {
|
||||
body?: NavigationTree;
|
||||
}
|
||||
namespace IndentStyle {
|
||||
type None = "None";
|
||||
type Block = "Block";
|
||||
type Smart = "Smart";
|
||||
}
|
||||
type IndentStyle = IndentStyle.None | IndentStyle.Block | IndentStyle.Smart;
|
||||
interface EditorSettings {
|
||||
baseIndentSize?: number;
|
||||
indentSize?: number;
|
||||
tabSize?: number;
|
||||
newLineCharacter?: string;
|
||||
convertTabsToSpaces?: boolean;
|
||||
indentStyle?: IndentStyle | ts.IndentStyle;
|
||||
}
|
||||
interface FormatCodeSettings extends EditorSettings {
|
||||
insertSpaceAfterCommaDelimiter?: boolean;
|
||||
insertSpaceAfterSemicolonInForStatements?: boolean;
|
||||
insertSpaceBeforeAndAfterBinaryOperators?: boolean;
|
||||
insertSpaceAfterKeywordsInControlFlowStatements?: boolean;
|
||||
insertSpaceAfterFunctionKeywordForAnonymousFunctions?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean;
|
||||
placeOpenBraceOnNewLineForFunctions?: boolean;
|
||||
placeOpenBraceOnNewLineForControlBlocks?: boolean;
|
||||
}
|
||||
interface CompilerOptions {
|
||||
allowJs?: boolean;
|
||||
allowSyntheticDefaultImports?: boolean;
|
||||
allowUnreachableCode?: boolean;
|
||||
allowUnusedLabels?: boolean;
|
||||
baseUrl?: string;
|
||||
charset?: string;
|
||||
declaration?: boolean;
|
||||
declarationDir?: string;
|
||||
disableSizeLimit?: boolean;
|
||||
emitBOM?: boolean;
|
||||
emitDecoratorMetadata?: boolean;
|
||||
experimentalDecorators?: boolean;
|
||||
forceConsistentCasingInFileNames?: boolean;
|
||||
inlineSourceMap?: boolean;
|
||||
inlineSources?: boolean;
|
||||
isolatedModules?: boolean;
|
||||
jsx?: JsxEmit | ts.JsxEmit;
|
||||
lib?: string[];
|
||||
locale?: string;
|
||||
mapRoot?: string;
|
||||
maxNodeModuleJsDepth?: number;
|
||||
module?: ModuleKind | ts.ModuleKind;
|
||||
moduleResolution?: ModuleResolutionKind | ts.ModuleResolutionKind;
|
||||
newLine?: NewLineKind | ts.NewLineKind;
|
||||
noEmit?: boolean;
|
||||
noEmitHelpers?: boolean;
|
||||
noEmitOnError?: boolean;
|
||||
noErrorTruncation?: boolean;
|
||||
noFallthroughCasesInSwitch?: boolean;
|
||||
noImplicitAny?: boolean;
|
||||
noImplicitReturns?: boolean;
|
||||
noImplicitThis?: boolean;
|
||||
noUnusedLocals?: boolean;
|
||||
noUnusedParameters?: boolean;
|
||||
noImplicitUseStrict?: boolean;
|
||||
noLib?: boolean;
|
||||
noResolve?: boolean;
|
||||
out?: string;
|
||||
outDir?: string;
|
||||
outFile?: string;
|
||||
paths?: MapLike<string[]>;
|
||||
preserveConstEnums?: boolean;
|
||||
project?: string;
|
||||
reactNamespace?: string;
|
||||
removeComments?: boolean;
|
||||
rootDir?: string;
|
||||
rootDirs?: string[];
|
||||
skipLibCheck?: boolean;
|
||||
skipDefaultLibCheck?: boolean;
|
||||
sourceMap?: boolean;
|
||||
sourceRoot?: string;
|
||||
strictNullChecks?: boolean;
|
||||
suppressExcessPropertyErrors?: boolean;
|
||||
suppressImplicitAnyIndexErrors?: boolean;
|
||||
target?: ScriptTarget | ts.ScriptTarget;
|
||||
traceResolution?: boolean;
|
||||
types?: string[];
|
||||
/** Paths used to used to compute primary types search locations */
|
||||
typeRoots?: string[];
|
||||
[option: string]: CompilerOptionsValue | undefined;
|
||||
}
|
||||
namespace JsxEmit {
|
||||
type None = "None";
|
||||
type Preserve = "Preserve";
|
||||
type React = "React";
|
||||
}
|
||||
type JsxEmit = JsxEmit.None | JsxEmit.Preserve | JsxEmit.React;
|
||||
namespace ModuleKind {
|
||||
type None = "None";
|
||||
type CommonJS = "CommonJS";
|
||||
type AMD = "AMD";
|
||||
type UMD = "UMD";
|
||||
type System = "System";
|
||||
type ES6 = "ES6";
|
||||
type ES2015 = "ES2015";
|
||||
}
|
||||
type ModuleKind = ModuleKind.None | ModuleKind.CommonJS | ModuleKind.AMD | ModuleKind.UMD | ModuleKind.System | ModuleKind.ES6 | ModuleKind.ES2015;
|
||||
namespace ModuleResolutionKind {
|
||||
type Classic = "Classic";
|
||||
type Node = "Node";
|
||||
}
|
||||
type ModuleResolutionKind = ModuleResolutionKind.Classic | ModuleResolutionKind.Node;
|
||||
namespace NewLineKind {
|
||||
type Crlf = "Crlf";
|
||||
type Lf = "Lf";
|
||||
}
|
||||
type NewLineKind = NewLineKind.Crlf | NewLineKind.Lf;
|
||||
namespace ScriptTarget {
|
||||
type ES3 = "ES3";
|
||||
type ES5 = "ES5";
|
||||
type ES6 = "ES6";
|
||||
type ES2015 = "ES2015";
|
||||
}
|
||||
type ScriptTarget = ScriptTarget.ES3 | ScriptTarget.ES5 | ScriptTarget.ES6 | ScriptTarget.ES2015;
|
||||
}
|
||||
declare namespace ts.server.protocol {
|
||||
|
||||
@@ -1695,29 +1783,6 @@ declare namespace ts.server.protocol {
|
||||
position: number;
|
||||
}
|
||||
|
||||
interface EditorSettings {
|
||||
baseIndentSize?: number;
|
||||
indentSize?: number;
|
||||
tabSize?: number;
|
||||
newLineCharacter?: string;
|
||||
convertTabsToSpaces?: boolean;
|
||||
indentStyle?: IndentStyle;
|
||||
}
|
||||
|
||||
enum IndentStyle {
|
||||
None = 0,
|
||||
Block = 1,
|
||||
Smart = 2,
|
||||
}
|
||||
|
||||
enum ScriptKind {
|
||||
Unknown = 0,
|
||||
JS = 1,
|
||||
JSX = 2,
|
||||
TS = 3,
|
||||
TSX = 4,
|
||||
}
|
||||
|
||||
interface TypingOptions {
|
||||
enableAutoDiscovery?: boolean;
|
||||
include?: string[];
|
||||
@@ -1725,124 +1790,22 @@ declare namespace ts.server.protocol {
|
||||
[option: string]: string[] | boolean | undefined;
|
||||
}
|
||||
|
||||
interface CompilerOptions {
|
||||
allowJs?: boolean;
|
||||
allowSyntheticDefaultImports?: boolean;
|
||||
allowUnreachableCode?: boolean;
|
||||
allowUnusedLabels?: boolean;
|
||||
alwaysStrict?: boolean;
|
||||
baseUrl?: string;
|
||||
charset?: string;
|
||||
declaration?: boolean;
|
||||
declarationDir?: string;
|
||||
disableSizeLimit?: boolean;
|
||||
emitBOM?: boolean;
|
||||
emitDecoratorMetadata?: boolean;
|
||||
experimentalDecorators?: boolean;
|
||||
forceConsistentCasingInFileNames?: boolean;
|
||||
importHelpers?: boolean;
|
||||
inlineSourceMap?: boolean;
|
||||
inlineSources?: boolean;
|
||||
isolatedModules?: boolean;
|
||||
jsx?: JsxEmit;
|
||||
lib?: string[];
|
||||
locale?: string;
|
||||
mapRoot?: string;
|
||||
maxNodeModuleJsDepth?: number;
|
||||
module?: ModuleKind;
|
||||
moduleResolution?: ModuleResolutionKind;
|
||||
newLine?: NewLineKind;
|
||||
noEmit?: boolean;
|
||||
noEmitHelpers?: boolean;
|
||||
noEmitOnError?: boolean;
|
||||
noErrorTruncation?: boolean;
|
||||
noFallthroughCasesInSwitch?: boolean;
|
||||
noImplicitAny?: boolean;
|
||||
noImplicitReturns?: boolean;
|
||||
noImplicitThis?: boolean;
|
||||
noUnusedLocals?: boolean;
|
||||
noUnusedParameters?: boolean;
|
||||
noImplicitUseStrict?: boolean;
|
||||
noLib?: boolean;
|
||||
noResolve?: boolean;
|
||||
out?: string;
|
||||
outDir?: string;
|
||||
outFile?: string;
|
||||
paths?: MapLike<string[]>;
|
||||
preserveConstEnums?: boolean;
|
||||
project?: string;
|
||||
reactNamespace?: string;
|
||||
removeComments?: boolean;
|
||||
rootDir?: string;
|
||||
rootDirs?: string[];
|
||||
skipLibCheck?: boolean;
|
||||
skipDefaultLibCheck?: boolean;
|
||||
sourceMap?: boolean;
|
||||
sourceRoot?: string;
|
||||
strictNullChecks?: boolean;
|
||||
suppressExcessPropertyErrors?: boolean;
|
||||
suppressImplicitAnyIndexErrors?: boolean;
|
||||
target?: ScriptTarget;
|
||||
traceResolution?: boolean;
|
||||
types?: string[];
|
||||
/** Paths used to used to compute primary types search locations */
|
||||
typeRoots?: string[];
|
||||
[option: string]: CompilerOptionsValue | undefined;
|
||||
}
|
||||
|
||||
enum JsxEmit {
|
||||
None = 0,
|
||||
Preserve = 1,
|
||||
React = 2,
|
||||
}
|
||||
|
||||
enum ModuleKind {
|
||||
None = 0,
|
||||
CommonJS = 1,
|
||||
AMD = 2,
|
||||
UMD = 3,
|
||||
System = 4,
|
||||
ES6 = 5,
|
||||
ES2015 = 5,
|
||||
}
|
||||
|
||||
enum ModuleResolutionKind {
|
||||
Classic = 1,
|
||||
NodeJs = 2,
|
||||
}
|
||||
|
||||
enum NewLineKind {
|
||||
CarriageReturnLineFeed = 0,
|
||||
LineFeed = 1,
|
||||
}
|
||||
|
||||
interface MapLike<T> {
|
||||
[index: string]: T;
|
||||
}
|
||||
|
||||
enum ScriptTarget {
|
||||
ES3 = 0,
|
||||
ES5 = 1,
|
||||
ES6 = 2,
|
||||
ES2015 = 2,
|
||||
Latest = 2,
|
||||
}
|
||||
|
||||
type CompilerOptionsValue = string | number | boolean | (string | number)[] | string[] | MapLike<string[]>;
|
||||
|
||||
interface FormatCodeSettings extends EditorSettings {
|
||||
insertSpaceAfterCommaDelimiter?: boolean;
|
||||
insertSpaceAfterSemicolonInForStatements?: boolean;
|
||||
insertSpaceBeforeAndAfterBinaryOperators?: boolean;
|
||||
insertSpaceAfterKeywordsInControlFlowStatements?: boolean;
|
||||
insertSpaceAfterFunctionKeywordForAnonymousFunctions?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean;
|
||||
insertSpaceAfterTypeAssertion?: boolean;
|
||||
placeOpenBraceOnNewLineForFunctions?: boolean;
|
||||
placeOpenBraceOnNewLineForControlBlocks?: boolean;
|
||||
}
|
||||
}
|
||||
}
|
||||
declare namespace ts {
|
||||
// these types are empty stubs for types from services and should not be used directly
|
||||
export type ScriptKind = never;
|
||||
export type IndentStyle = never;
|
||||
export type JsxEmit = never;
|
||||
export type ModuleKind = never;
|
||||
export type ModuleResolutionKind = never;
|
||||
export type NewLineKind = never;
|
||||
export type ScriptTarget = never;
|
||||
}
|
||||
import protocol = ts.server.protocol;
|
||||
export = protocol;
|
||||
export as namespace protocol;
|
||||
+8486
-7770
File diff suppressed because it is too large
Load Diff
+15250
-14407
File diff suppressed because it is too large
Load Diff
Vendored
+8577
-1127
File diff suppressed because one or more lines are too long
+15163
-14382
File diff suppressed because it is too large
Load Diff
Vendored
+323
-213
@@ -163,170 +163,177 @@ declare namespace ts {
|
||||
DeclareKeyword = 123,
|
||||
GetKeyword = 124,
|
||||
IsKeyword = 125,
|
||||
ModuleKeyword = 126,
|
||||
NamespaceKeyword = 127,
|
||||
NeverKeyword = 128,
|
||||
ReadonlyKeyword = 129,
|
||||
RequireKeyword = 130,
|
||||
NumberKeyword = 131,
|
||||
SetKeyword = 132,
|
||||
StringKeyword = 133,
|
||||
SymbolKeyword = 134,
|
||||
TypeKeyword = 135,
|
||||
UndefinedKeyword = 136,
|
||||
FromKeyword = 137,
|
||||
GlobalKeyword = 138,
|
||||
OfKeyword = 139,
|
||||
QualifiedName = 140,
|
||||
ComputedPropertyName = 141,
|
||||
TypeParameter = 142,
|
||||
Parameter = 143,
|
||||
Decorator = 144,
|
||||
PropertySignature = 145,
|
||||
PropertyDeclaration = 146,
|
||||
MethodSignature = 147,
|
||||
MethodDeclaration = 148,
|
||||
Constructor = 149,
|
||||
GetAccessor = 150,
|
||||
SetAccessor = 151,
|
||||
CallSignature = 152,
|
||||
ConstructSignature = 153,
|
||||
IndexSignature = 154,
|
||||
TypePredicate = 155,
|
||||
TypeReference = 156,
|
||||
FunctionType = 157,
|
||||
ConstructorType = 158,
|
||||
TypeQuery = 159,
|
||||
TypeLiteral = 160,
|
||||
ArrayType = 161,
|
||||
TupleType = 162,
|
||||
UnionType = 163,
|
||||
IntersectionType = 164,
|
||||
ParenthesizedType = 165,
|
||||
ThisType = 166,
|
||||
LiteralType = 167,
|
||||
ObjectBindingPattern = 168,
|
||||
ArrayBindingPattern = 169,
|
||||
BindingElement = 170,
|
||||
ArrayLiteralExpression = 171,
|
||||
ObjectLiteralExpression = 172,
|
||||
PropertyAccessExpression = 173,
|
||||
ElementAccessExpression = 174,
|
||||
CallExpression = 175,
|
||||
NewExpression = 176,
|
||||
TaggedTemplateExpression = 177,
|
||||
TypeAssertionExpression = 178,
|
||||
ParenthesizedExpression = 179,
|
||||
FunctionExpression = 180,
|
||||
ArrowFunction = 181,
|
||||
DeleteExpression = 182,
|
||||
TypeOfExpression = 183,
|
||||
VoidExpression = 184,
|
||||
AwaitExpression = 185,
|
||||
PrefixUnaryExpression = 186,
|
||||
PostfixUnaryExpression = 187,
|
||||
BinaryExpression = 188,
|
||||
ConditionalExpression = 189,
|
||||
TemplateExpression = 190,
|
||||
YieldExpression = 191,
|
||||
SpreadElementExpression = 192,
|
||||
ClassExpression = 193,
|
||||
OmittedExpression = 194,
|
||||
ExpressionWithTypeArguments = 195,
|
||||
AsExpression = 196,
|
||||
NonNullExpression = 197,
|
||||
TemplateSpan = 198,
|
||||
SemicolonClassElement = 199,
|
||||
Block = 200,
|
||||
VariableStatement = 201,
|
||||
EmptyStatement = 202,
|
||||
ExpressionStatement = 203,
|
||||
IfStatement = 204,
|
||||
DoStatement = 205,
|
||||
WhileStatement = 206,
|
||||
ForStatement = 207,
|
||||
ForInStatement = 208,
|
||||
ForOfStatement = 209,
|
||||
ContinueStatement = 210,
|
||||
BreakStatement = 211,
|
||||
ReturnStatement = 212,
|
||||
WithStatement = 213,
|
||||
SwitchStatement = 214,
|
||||
LabeledStatement = 215,
|
||||
ThrowStatement = 216,
|
||||
TryStatement = 217,
|
||||
DebuggerStatement = 218,
|
||||
VariableDeclaration = 219,
|
||||
VariableDeclarationList = 220,
|
||||
FunctionDeclaration = 221,
|
||||
ClassDeclaration = 222,
|
||||
InterfaceDeclaration = 223,
|
||||
TypeAliasDeclaration = 224,
|
||||
EnumDeclaration = 225,
|
||||
ModuleDeclaration = 226,
|
||||
ModuleBlock = 227,
|
||||
CaseBlock = 228,
|
||||
NamespaceExportDeclaration = 229,
|
||||
ImportEqualsDeclaration = 230,
|
||||
ImportDeclaration = 231,
|
||||
ImportClause = 232,
|
||||
NamespaceImport = 233,
|
||||
NamedImports = 234,
|
||||
ImportSpecifier = 235,
|
||||
ExportAssignment = 236,
|
||||
ExportDeclaration = 237,
|
||||
NamedExports = 238,
|
||||
ExportSpecifier = 239,
|
||||
MissingDeclaration = 240,
|
||||
ExternalModuleReference = 241,
|
||||
JsxElement = 242,
|
||||
JsxSelfClosingElement = 243,
|
||||
JsxOpeningElement = 244,
|
||||
JsxClosingElement = 245,
|
||||
JsxAttribute = 246,
|
||||
JsxSpreadAttribute = 247,
|
||||
JsxExpression = 248,
|
||||
CaseClause = 249,
|
||||
DefaultClause = 250,
|
||||
HeritageClause = 251,
|
||||
CatchClause = 252,
|
||||
PropertyAssignment = 253,
|
||||
ShorthandPropertyAssignment = 254,
|
||||
EnumMember = 255,
|
||||
SourceFile = 256,
|
||||
JSDocTypeExpression = 257,
|
||||
JSDocAllType = 258,
|
||||
JSDocUnknownType = 259,
|
||||
JSDocArrayType = 260,
|
||||
JSDocUnionType = 261,
|
||||
JSDocTupleType = 262,
|
||||
JSDocNullableType = 263,
|
||||
JSDocNonNullableType = 264,
|
||||
JSDocRecordType = 265,
|
||||
JSDocRecordMember = 266,
|
||||
JSDocTypeReference = 267,
|
||||
JSDocOptionalType = 268,
|
||||
JSDocFunctionType = 269,
|
||||
JSDocVariadicType = 270,
|
||||
JSDocConstructorType = 271,
|
||||
JSDocThisType = 272,
|
||||
JSDocComment = 273,
|
||||
JSDocTag = 274,
|
||||
JSDocParameterTag = 275,
|
||||
JSDocReturnTag = 276,
|
||||
JSDocTypeTag = 277,
|
||||
JSDocTemplateTag = 278,
|
||||
JSDocTypedefTag = 279,
|
||||
JSDocPropertyTag = 280,
|
||||
JSDocTypeLiteral = 281,
|
||||
JSDocLiteralType = 282,
|
||||
JSDocNullKeyword = 283,
|
||||
JSDocUndefinedKeyword = 284,
|
||||
JSDocNeverKeyword = 285,
|
||||
SyntaxList = 286,
|
||||
NotEmittedStatement = 287,
|
||||
PartiallyEmittedExpression = 288,
|
||||
Count = 289,
|
||||
KeyOfKeyword = 126,
|
||||
ModuleKeyword = 127,
|
||||
NamespaceKeyword = 128,
|
||||
NeverKeyword = 129,
|
||||
ReadonlyKeyword = 130,
|
||||
RequireKeyword = 131,
|
||||
NumberKeyword = 132,
|
||||
SetKeyword = 133,
|
||||
StringKeyword = 134,
|
||||
SymbolKeyword = 135,
|
||||
TypeKeyword = 136,
|
||||
UndefinedKeyword = 137,
|
||||
FromKeyword = 138,
|
||||
GlobalKeyword = 139,
|
||||
OfKeyword = 140,
|
||||
QualifiedName = 141,
|
||||
ComputedPropertyName = 142,
|
||||
TypeParameter = 143,
|
||||
Parameter = 144,
|
||||
Decorator = 145,
|
||||
PropertySignature = 146,
|
||||
PropertyDeclaration = 147,
|
||||
MethodSignature = 148,
|
||||
MethodDeclaration = 149,
|
||||
Constructor = 150,
|
||||
GetAccessor = 151,
|
||||
SetAccessor = 152,
|
||||
CallSignature = 153,
|
||||
ConstructSignature = 154,
|
||||
IndexSignature = 155,
|
||||
TypePredicate = 156,
|
||||
TypeReference = 157,
|
||||
FunctionType = 158,
|
||||
ConstructorType = 159,
|
||||
TypeQuery = 160,
|
||||
TypeLiteral = 161,
|
||||
ArrayType = 162,
|
||||
TupleType = 163,
|
||||
UnionType = 164,
|
||||
IntersectionType = 165,
|
||||
ParenthesizedType = 166,
|
||||
ThisType = 167,
|
||||
TypeOperator = 168,
|
||||
IndexedAccessType = 169,
|
||||
MappedType = 170,
|
||||
LiteralType = 171,
|
||||
ObjectBindingPattern = 172,
|
||||
ArrayBindingPattern = 173,
|
||||
BindingElement = 174,
|
||||
ArrayLiteralExpression = 175,
|
||||
ObjectLiteralExpression = 176,
|
||||
PropertyAccessExpression = 177,
|
||||
ElementAccessExpression = 178,
|
||||
CallExpression = 179,
|
||||
NewExpression = 180,
|
||||
TaggedTemplateExpression = 181,
|
||||
TypeAssertionExpression = 182,
|
||||
ParenthesizedExpression = 183,
|
||||
FunctionExpression = 184,
|
||||
ArrowFunction = 185,
|
||||
DeleteExpression = 186,
|
||||
TypeOfExpression = 187,
|
||||
VoidExpression = 188,
|
||||
AwaitExpression = 189,
|
||||
PrefixUnaryExpression = 190,
|
||||
PostfixUnaryExpression = 191,
|
||||
BinaryExpression = 192,
|
||||
ConditionalExpression = 193,
|
||||
TemplateExpression = 194,
|
||||
YieldExpression = 195,
|
||||
SpreadElement = 196,
|
||||
ClassExpression = 197,
|
||||
OmittedExpression = 198,
|
||||
ExpressionWithTypeArguments = 199,
|
||||
AsExpression = 200,
|
||||
NonNullExpression = 201,
|
||||
TemplateSpan = 202,
|
||||
SemicolonClassElement = 203,
|
||||
Block = 204,
|
||||
VariableStatement = 205,
|
||||
EmptyStatement = 206,
|
||||
ExpressionStatement = 207,
|
||||
IfStatement = 208,
|
||||
DoStatement = 209,
|
||||
WhileStatement = 210,
|
||||
ForStatement = 211,
|
||||
ForInStatement = 212,
|
||||
ForOfStatement = 213,
|
||||
ContinueStatement = 214,
|
||||
BreakStatement = 215,
|
||||
ReturnStatement = 216,
|
||||
WithStatement = 217,
|
||||
SwitchStatement = 218,
|
||||
LabeledStatement = 219,
|
||||
ThrowStatement = 220,
|
||||
TryStatement = 221,
|
||||
DebuggerStatement = 222,
|
||||
VariableDeclaration = 223,
|
||||
VariableDeclarationList = 224,
|
||||
FunctionDeclaration = 225,
|
||||
ClassDeclaration = 226,
|
||||
InterfaceDeclaration = 227,
|
||||
TypeAliasDeclaration = 228,
|
||||
EnumDeclaration = 229,
|
||||
ModuleDeclaration = 230,
|
||||
ModuleBlock = 231,
|
||||
CaseBlock = 232,
|
||||
NamespaceExportDeclaration = 233,
|
||||
ImportEqualsDeclaration = 234,
|
||||
ImportDeclaration = 235,
|
||||
ImportClause = 236,
|
||||
NamespaceImport = 237,
|
||||
NamedImports = 238,
|
||||
ImportSpecifier = 239,
|
||||
ExportAssignment = 240,
|
||||
ExportDeclaration = 241,
|
||||
NamedExports = 242,
|
||||
ExportSpecifier = 243,
|
||||
MissingDeclaration = 244,
|
||||
ExternalModuleReference = 245,
|
||||
JsxElement = 246,
|
||||
JsxSelfClosingElement = 247,
|
||||
JsxOpeningElement = 248,
|
||||
JsxClosingElement = 249,
|
||||
JsxAttribute = 250,
|
||||
JsxSpreadAttribute = 251,
|
||||
JsxExpression = 252,
|
||||
CaseClause = 253,
|
||||
DefaultClause = 254,
|
||||
HeritageClause = 255,
|
||||
CatchClause = 256,
|
||||
PropertyAssignment = 257,
|
||||
ShorthandPropertyAssignment = 258,
|
||||
SpreadAssignment = 259,
|
||||
EnumMember = 260,
|
||||
SourceFile = 261,
|
||||
JSDocTypeExpression = 262,
|
||||
JSDocAllType = 263,
|
||||
JSDocUnknownType = 264,
|
||||
JSDocArrayType = 265,
|
||||
JSDocUnionType = 266,
|
||||
JSDocTupleType = 267,
|
||||
JSDocNullableType = 268,
|
||||
JSDocNonNullableType = 269,
|
||||
JSDocRecordType = 270,
|
||||
JSDocRecordMember = 271,
|
||||
JSDocTypeReference = 272,
|
||||
JSDocOptionalType = 273,
|
||||
JSDocFunctionType = 274,
|
||||
JSDocVariadicType = 275,
|
||||
JSDocConstructorType = 276,
|
||||
JSDocThisType = 277,
|
||||
JSDocComment = 278,
|
||||
JSDocTag = 279,
|
||||
JSDocParameterTag = 280,
|
||||
JSDocReturnTag = 281,
|
||||
JSDocTypeTag = 282,
|
||||
JSDocTemplateTag = 283,
|
||||
JSDocTypedefTag = 284,
|
||||
JSDocPropertyTag = 285,
|
||||
JSDocTypeLiteral = 286,
|
||||
JSDocLiteralType = 287,
|
||||
JSDocNullKeyword = 288,
|
||||
JSDocUndefinedKeyword = 289,
|
||||
JSDocNeverKeyword = 290,
|
||||
SyntaxList = 291,
|
||||
NotEmittedStatement = 292,
|
||||
PartiallyEmittedExpression = 293,
|
||||
MergeDeclarationMarker = 294,
|
||||
EndOfDeclarationMarker = 295,
|
||||
Count = 296,
|
||||
FirstAssignment = 57,
|
||||
LastAssignment = 69,
|
||||
FirstCompoundAssignment = 58,
|
||||
@@ -334,15 +341,15 @@ declare namespace ts {
|
||||
FirstReservedWord = 71,
|
||||
LastReservedWord = 106,
|
||||
FirstKeyword = 71,
|
||||
LastKeyword = 139,
|
||||
LastKeyword = 140,
|
||||
FirstFutureReservedWord = 107,
|
||||
LastFutureReservedWord = 115,
|
||||
FirstTypeNode = 155,
|
||||
LastTypeNode = 167,
|
||||
FirstTypeNode = 156,
|
||||
LastTypeNode = 171,
|
||||
FirstPunctuation = 16,
|
||||
LastPunctuation = 69,
|
||||
FirstToken = 0,
|
||||
LastToken = 139,
|
||||
LastToken = 140,
|
||||
FirstTriviaToken = 2,
|
||||
LastTriviaToken = 7,
|
||||
FirstLiteralToken = 8,
|
||||
@@ -351,11 +358,11 @@ declare namespace ts {
|
||||
LastTemplateToken = 15,
|
||||
FirstBinaryOperator = 26,
|
||||
LastBinaryOperator = 69,
|
||||
FirstNode = 140,
|
||||
FirstJSDocNode = 257,
|
||||
LastJSDocNode = 282,
|
||||
FirstJSDocTagNode = 273,
|
||||
LastJSDocTagNode = 285,
|
||||
FirstNode = 141,
|
||||
FirstJSDocNode = 262,
|
||||
LastJSDocNode = 287,
|
||||
FirstJSDocTagNode = 278,
|
||||
LastJSDocTagNode = 290,
|
||||
}
|
||||
enum NodeFlags {
|
||||
None = 0,
|
||||
@@ -373,21 +380,22 @@ declare namespace ts {
|
||||
HasDecorators = 2048,
|
||||
HasParamDecorators = 4096,
|
||||
HasAsyncFunctions = 8192,
|
||||
HasJsxSpreadAttributes = 16384,
|
||||
DisallowInContext = 32768,
|
||||
YieldContext = 65536,
|
||||
DecoratorContext = 131072,
|
||||
AwaitContext = 262144,
|
||||
ThisNodeHasError = 524288,
|
||||
JavaScriptFile = 1048576,
|
||||
ThisNodeOrAnySubNodesHasError = 2097152,
|
||||
HasAggregatedChildData = 4194304,
|
||||
HasSpreadAttribute = 16384,
|
||||
HasRestAttribute = 32768,
|
||||
DisallowInContext = 65536,
|
||||
YieldContext = 131072,
|
||||
DecoratorContext = 262144,
|
||||
AwaitContext = 524288,
|
||||
ThisNodeHasError = 1048576,
|
||||
JavaScriptFile = 2097152,
|
||||
ThisNodeOrAnySubNodesHasError = 4194304,
|
||||
HasAggregatedChildData = 8388608,
|
||||
BlockScoped = 3,
|
||||
ReachabilityCheckFlags = 384,
|
||||
EmitHelperFlags = 31744,
|
||||
ReachabilityAndEmitFlags = 32128,
|
||||
ContextFlags = 1540096,
|
||||
TypeExcludesFlags = 327680,
|
||||
EmitHelperFlags = 64512,
|
||||
ReachabilityAndEmitFlags = 64896,
|
||||
ContextFlags = 3080192,
|
||||
TypeExcludesFlags = 655360,
|
||||
}
|
||||
enum ModifierFlags {
|
||||
None = 0,
|
||||
@@ -407,6 +415,7 @@ declare namespace ts {
|
||||
ParameterPropertyModifier = 92,
|
||||
NonPublicAccessibilityModifier = 24,
|
||||
TypeScriptModifier = 2270,
|
||||
ExportDefault = 513,
|
||||
}
|
||||
enum JsxFlags {
|
||||
None = 0,
|
||||
@@ -437,12 +446,14 @@ declare namespace ts {
|
||||
type EqualsGreaterThanToken = Token<SyntaxKind.EqualsGreaterThanToken>;
|
||||
type EndOfFileToken = Token<SyntaxKind.EndOfFileToken>;
|
||||
type AtToken = Token<SyntaxKind.AtToken>;
|
||||
type ReadonlyToken = Token<SyntaxKind.ReadonlyKeyword>;
|
||||
type Modifier = Token<SyntaxKind.AbstractKeyword> | Token<SyntaxKind.AsyncKeyword> | Token<SyntaxKind.ConstKeyword> | Token<SyntaxKind.DeclareKeyword> | Token<SyntaxKind.DefaultKeyword> | Token<SyntaxKind.ExportKeyword> | Token<SyntaxKind.PublicKeyword> | Token<SyntaxKind.PrivateKeyword> | Token<SyntaxKind.ProtectedKeyword> | Token<SyntaxKind.ReadonlyKeyword> | Token<SyntaxKind.StaticKeyword>;
|
||||
type ModifiersArray = NodeArray<Modifier>;
|
||||
interface Identifier extends PrimaryExpression {
|
||||
kind: SyntaxKind.Identifier;
|
||||
text: string;
|
||||
originalKeywordKind?: SyntaxKind;
|
||||
isInJSDocNamespace?: boolean;
|
||||
}
|
||||
interface TransientIdentifier extends Identifier {
|
||||
resolvedSymbol: Symbol;
|
||||
@@ -533,7 +544,7 @@ declare namespace ts {
|
||||
_objectLiteralBrandBrand: any;
|
||||
name?: PropertyName;
|
||||
}
|
||||
type ObjectLiteralElementLike = PropertyAssignment | ShorthandPropertyAssignment | MethodDeclaration | AccessorDeclaration;
|
||||
type ObjectLiteralElementLike = PropertyAssignment | ShorthandPropertyAssignment | MethodDeclaration | AccessorDeclaration | SpreadAssignment;
|
||||
interface PropertyAssignment extends ObjectLiteralElement {
|
||||
kind: SyntaxKind.PropertyAssignment;
|
||||
name: PropertyName;
|
||||
@@ -547,6 +558,10 @@ declare namespace ts {
|
||||
equalsToken?: Token<SyntaxKind.EqualsToken>;
|
||||
objectAssignmentInitializer?: Expression;
|
||||
}
|
||||
interface SpreadAssignment extends ObjectLiteralElement {
|
||||
kind: SyntaxKind.SpreadAssignment;
|
||||
expression: Expression;
|
||||
}
|
||||
interface VariableLikeDeclaration extends Declaration {
|
||||
propertyName?: PropertyName;
|
||||
dotDotDotToken?: DotDotDotToken;
|
||||
@@ -677,6 +692,23 @@ declare namespace ts {
|
||||
kind: SyntaxKind.ParenthesizedType;
|
||||
type: TypeNode;
|
||||
}
|
||||
interface TypeOperatorNode extends TypeNode {
|
||||
kind: SyntaxKind.TypeOperator;
|
||||
operator: SyntaxKind.KeyOfKeyword;
|
||||
type: TypeNode;
|
||||
}
|
||||
interface IndexedAccessTypeNode extends TypeNode {
|
||||
kind: SyntaxKind.IndexedAccessType;
|
||||
objectType: TypeNode;
|
||||
indexType: TypeNode;
|
||||
}
|
||||
interface MappedTypeNode extends TypeNode, Declaration {
|
||||
kind: SyntaxKind.MappedType;
|
||||
readonlyToken?: ReadonlyToken;
|
||||
typeParameter: TypeParameterDeclaration;
|
||||
questionToken?: QuestionToken;
|
||||
type?: TypeNode;
|
||||
}
|
||||
interface LiteralTypeNode extends TypeNode {
|
||||
kind: SyntaxKind.LiteralType;
|
||||
literal: Expression;
|
||||
@@ -709,9 +741,6 @@ declare namespace ts {
|
||||
operand: LeftHandSideExpression;
|
||||
operator: PostfixUnaryOperator;
|
||||
}
|
||||
interface PostfixExpression extends UnaryExpression {
|
||||
_postfixExpressionBrand: any;
|
||||
}
|
||||
interface LeftHandSideExpression extends IncrementExpression {
|
||||
_leftHandSideExpressionBrand: any;
|
||||
}
|
||||
@@ -780,6 +809,17 @@ declare namespace ts {
|
||||
operatorToken: BinaryOperatorToken;
|
||||
right: Expression;
|
||||
}
|
||||
interface AssignmentExpression extends BinaryExpression {
|
||||
left: LeftHandSideExpression;
|
||||
operatorToken: Token<SyntaxKind.EqualsToken>;
|
||||
}
|
||||
interface ObjectDestructuringAssignment extends AssignmentExpression {
|
||||
left: ObjectLiteralExpression;
|
||||
}
|
||||
interface ArrayDestructuringAssignment extends AssignmentExpression {
|
||||
left: ArrayLiteralExpression;
|
||||
}
|
||||
type DestructuringAssignment = ObjectDestructuringAssignment | ArrayDestructuringAssignment;
|
||||
interface ConditionalExpression extends Expression {
|
||||
kind: SyntaxKind.ConditionalExpression;
|
||||
condition: Expression;
|
||||
@@ -846,8 +886,8 @@ declare namespace ts {
|
||||
kind: SyntaxKind.ArrayLiteralExpression;
|
||||
elements: NodeArray<Expression>;
|
||||
}
|
||||
interface SpreadElementExpression extends Expression {
|
||||
kind: SyntaxKind.SpreadElementExpression;
|
||||
interface SpreadElement extends Expression {
|
||||
kind: SyntaxKind.SpreadElement;
|
||||
expression: Expression;
|
||||
}
|
||||
/**
|
||||
@@ -1141,12 +1181,16 @@ declare namespace ts {
|
||||
interface ModuleDeclaration extends DeclarationStatement {
|
||||
kind: SyntaxKind.ModuleDeclaration;
|
||||
name: Identifier | LiteralExpression;
|
||||
body?: ModuleBlock | NamespaceDeclaration;
|
||||
body?: ModuleBlock | NamespaceDeclaration | JSDocNamespaceDeclaration | Identifier;
|
||||
}
|
||||
interface NamespaceDeclaration extends ModuleDeclaration {
|
||||
name: Identifier;
|
||||
body: ModuleBlock | NamespaceDeclaration;
|
||||
}
|
||||
interface JSDocNamespaceDeclaration extends ModuleDeclaration {
|
||||
name: Identifier;
|
||||
body: JSDocNamespaceDeclaration | Identifier;
|
||||
}
|
||||
interface ModuleBlock extends Node, Statement {
|
||||
kind: SyntaxKind.ModuleBlock;
|
||||
statements: NodeArray<Statement>;
|
||||
@@ -1318,6 +1362,7 @@ declare namespace ts {
|
||||
}
|
||||
interface JSDocTypedefTag extends JSDocTag, Declaration {
|
||||
kind: SyntaxKind.JSDocTypedefTag;
|
||||
fullName?: JSDocNamespaceDeclaration | Identifier;
|
||||
name?: Identifier;
|
||||
typeExpression?: JSDocTypeExpression;
|
||||
jsDocTypeLiteral?: JSDocTypeLiteral;
|
||||
@@ -1708,14 +1753,11 @@ declare namespace ts {
|
||||
Null = 4096,
|
||||
Never = 8192,
|
||||
TypeParameter = 16384,
|
||||
Class = 32768,
|
||||
Interface = 65536,
|
||||
Reference = 131072,
|
||||
Tuple = 262144,
|
||||
Union = 524288,
|
||||
Intersection = 1048576,
|
||||
Anonymous = 2097152,
|
||||
Instantiated = 4194304,
|
||||
Object = 32768,
|
||||
Union = 65536,
|
||||
Intersection = 131072,
|
||||
Index = 262144,
|
||||
IndexedAccess = 524288,
|
||||
Literal = 480,
|
||||
StringOrNumberLiteral = 96,
|
||||
PossiblyFalsy = 7406,
|
||||
@@ -1723,12 +1765,11 @@ declare namespace ts {
|
||||
NumberLike = 340,
|
||||
BooleanLike = 136,
|
||||
EnumLike = 272,
|
||||
ObjectType = 2588672,
|
||||
UnionOrIntersection = 1572864,
|
||||
StructuredType = 4161536,
|
||||
StructuredOrTypeParameter = 4177920,
|
||||
Narrowable = 4178943,
|
||||
NotUnionOrUnit = 2589185,
|
||||
UnionOrIntersection = 196608,
|
||||
StructuredType = 229376,
|
||||
StructuredOrTypeParameter = 507904,
|
||||
Narrowable = 1033215,
|
||||
NotUnionOrUnit = 33281,
|
||||
}
|
||||
type DestructuringPattern = BindingPattern | ObjectLiteralExpression | ArrayLiteralExpression;
|
||||
interface Type {
|
||||
@@ -1749,8 +1790,21 @@ declare namespace ts {
|
||||
interface EnumLiteralType extends LiteralType {
|
||||
baseType: EnumType & UnionType;
|
||||
}
|
||||
enum ObjectFlags {
|
||||
Class = 1,
|
||||
Interface = 2,
|
||||
Reference = 4,
|
||||
Tuple = 8,
|
||||
Anonymous = 16,
|
||||
Mapped = 32,
|
||||
Instantiated = 64,
|
||||
ObjectLiteral = 128,
|
||||
EvolvingArray = 256,
|
||||
ObjectLiteralPatternWithComputedProperties = 512,
|
||||
ClassOrInterface = 3,
|
||||
}
|
||||
interface ObjectType extends Type {
|
||||
isObjectLiteralPatternWithComputedProperties?: boolean;
|
||||
objectFlags: ObjectFlags;
|
||||
}
|
||||
interface InterfaceType extends ObjectType {
|
||||
typeParameters: TypeParameter[];
|
||||
@@ -1778,9 +1832,21 @@ declare namespace ts {
|
||||
}
|
||||
interface IntersectionType extends UnionOrIntersectionType {
|
||||
}
|
||||
type StructuredType = ObjectType | UnionType | IntersectionType;
|
||||
interface EvolvingArrayType extends ObjectType {
|
||||
elementType: Type;
|
||||
finalArrayType?: Type;
|
||||
}
|
||||
interface TypeParameter extends Type {
|
||||
constraint: Type;
|
||||
}
|
||||
interface IndexType extends Type {
|
||||
type: TypeParameter;
|
||||
}
|
||||
interface IndexedAccessType extends Type {
|
||||
objectType: Type;
|
||||
indexType: TypeParameter;
|
||||
}
|
||||
enum SignatureKind {
|
||||
Call = 0,
|
||||
Construct = 1,
|
||||
@@ -1882,6 +1948,7 @@ declare namespace ts {
|
||||
preserveConstEnums?: boolean;
|
||||
project?: string;
|
||||
reactNamespace?: string;
|
||||
jsxFactory?: string;
|
||||
removeComments?: boolean;
|
||||
rootDir?: string;
|
||||
rootDirs?: string[];
|
||||
@@ -1912,6 +1979,7 @@ declare namespace ts {
|
||||
packageNameToTypingLocation: Map<string>;
|
||||
typingOptions: TypingOptions;
|
||||
compilerOptions: CompilerOptions;
|
||||
unresolvedImports: ReadonlyArray<string>;
|
||||
}
|
||||
enum ModuleKind {
|
||||
None = 0,
|
||||
@@ -1947,12 +2015,14 @@ declare namespace ts {
|
||||
ES2015 = 2,
|
||||
ES2016 = 3,
|
||||
ES2017 = 4,
|
||||
Latest = 4,
|
||||
ESNext = 5,
|
||||
Latest = 5,
|
||||
}
|
||||
enum LanguageVariant {
|
||||
Standard = 0,
|
||||
JSX = 1,
|
||||
}
|
||||
/** Either a parsed command line or a parsed tsconfig.json */
|
||||
interface ParsedCommandLine {
|
||||
options: CompilerOptions;
|
||||
typingOptions?: TypingOptions;
|
||||
@@ -1979,12 +2049,45 @@ declare namespace ts {
|
||||
getCurrentDirectory?(): string;
|
||||
getDirectories?(path: string): string[];
|
||||
}
|
||||
/**
|
||||
* Represents the result of module resolution.
|
||||
* Module resolution will pick up tsx/jsx/js files even if '--jsx' and '--allowJs' are turned off.
|
||||
* The Program will then filter results based on these flags.
|
||||
*
|
||||
* Prefer to return a `ResolvedModuleFull` so that the file type does not have to be inferred.
|
||||
*/
|
||||
interface ResolvedModule {
|
||||
/** Path of the file the module was resolved to. */
|
||||
resolvedFileName: string;
|
||||
/**
|
||||
* Denotes if 'resolvedFileName' is isExternalLibraryImport and thus should be a proper external module:
|
||||
* - be a .d.ts file
|
||||
* - use top level imports\exports
|
||||
* - don't use tripleslash references
|
||||
*/
|
||||
isExternalLibraryImport?: boolean;
|
||||
}
|
||||
/**
|
||||
* ResolvedModule with an explicitly provided `extension` property.
|
||||
* Prefer this over `ResolvedModule`.
|
||||
*/
|
||||
interface ResolvedModuleFull extends ResolvedModule {
|
||||
/**
|
||||
* Extension of resolvedFileName. This must match what's at the end of resolvedFileName.
|
||||
* This is optional for backwards-compatibility, but will be added if not provided.
|
||||
*/
|
||||
extension: Extension;
|
||||
}
|
||||
enum Extension {
|
||||
Ts = 0,
|
||||
Tsx = 1,
|
||||
Dts = 2,
|
||||
Js = 3,
|
||||
Jsx = 4,
|
||||
LastTypeScriptExtension = 2,
|
||||
}
|
||||
interface ResolvedModuleWithFailedLookupLocations {
|
||||
resolvedModule: ResolvedModule;
|
||||
resolvedModule: ResolvedModuleFull | undefined;
|
||||
failedLookupLocations: string[];
|
||||
}
|
||||
interface ResolvedTypeReferenceDirective {
|
||||
@@ -2042,7 +2145,11 @@ declare namespace ts {
|
||||
readFile(path: string, encoding?: string): string;
|
||||
getFileSize?(path: string): number;
|
||||
writeFile(path: string, data: string, writeByteOrderMark?: boolean): void;
|
||||
watchFile?(path: string, callback: FileWatcherCallback): FileWatcher;
|
||||
/**
|
||||
* @pollingInterval - this parameter is used in polling-based watchers and ignored in watchers that
|
||||
* use native OS file watching
|
||||
*/
|
||||
watchFile?(path: string, callback: FileWatcherCallback, pollingInterval?: number): FileWatcher;
|
||||
watchDirectory?(path: string, callback: DirectoryWatcherCallback, recursive?: boolean): FileWatcher;
|
||||
resolvePath(path: string): string;
|
||||
fileExists(path: string): boolean;
|
||||
@@ -2057,6 +2164,8 @@ declare namespace ts {
|
||||
getMemoryUsage?(): number;
|
||||
exit(exitCode?: number): void;
|
||||
realpath?(path: string): string;
|
||||
setTimeout?(callback: (...args: any[]) => void, ms: number, ...args: any[]): any;
|
||||
clearTimeout?(timeoutId: any): void;
|
||||
}
|
||||
interface FileWatcher {
|
||||
close(): void;
|
||||
@@ -2159,6 +2268,7 @@ declare namespace ts {
|
||||
function createNode(kind: SyntaxKind, pos?: number, end?: number): Node;
|
||||
function forEachChild<T>(node: Node, cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T;
|
||||
function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean, scriptKind?: ScriptKind): SourceFile;
|
||||
function parseIsolatedEntityName(text: string, languageVersion: ScriptTarget): EntityName;
|
||||
function isExternalModule(file: SourceFile): boolean;
|
||||
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;
|
||||
}
|
||||
@@ -2172,7 +2282,7 @@ declare namespace ts {
|
||||
* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups
|
||||
* is assumed to be the same as root directory of the project.
|
||||
*/
|
||||
function resolveTypeReferenceDirective(typeReferenceDirectiveName: string, containingFile: string, options: CompilerOptions, host: ModuleResolutionHost): ResolvedTypeReferenceDirectiveWithFailedLookupLocations;
|
||||
function resolveTypeReferenceDirective(typeReferenceDirectiveName: string, containingFile: string | undefined, options: CompilerOptions, host: ModuleResolutionHost): ResolvedTypeReferenceDirectiveWithFailedLookupLocations;
|
||||
/**
|
||||
* Given a set of options, returns the set of type directive names
|
||||
* that should be included for this program automatically.
|
||||
@@ -2188,7 +2298,7 @@ declare namespace ts {
|
||||
}
|
||||
declare namespace ts {
|
||||
/** The version of the TypeScript compiler release */
|
||||
const version = "2.1.0";
|
||||
const version = "2.2.0";
|
||||
function findConfigFile(searchPath: string, fileExists: (fileName: string) => boolean, configName?: string): string;
|
||||
function resolveTripleslashReference(moduleName: string, containingFile: string): string;
|
||||
function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost;
|
||||
|
||||
+11985
-9262
File diff suppressed because it is too large
Load Diff
Vendored
+323
-213
@@ -163,170 +163,177 @@ declare namespace ts {
|
||||
DeclareKeyword = 123,
|
||||
GetKeyword = 124,
|
||||
IsKeyword = 125,
|
||||
ModuleKeyword = 126,
|
||||
NamespaceKeyword = 127,
|
||||
NeverKeyword = 128,
|
||||
ReadonlyKeyword = 129,
|
||||
RequireKeyword = 130,
|
||||
NumberKeyword = 131,
|
||||
SetKeyword = 132,
|
||||
StringKeyword = 133,
|
||||
SymbolKeyword = 134,
|
||||
TypeKeyword = 135,
|
||||
UndefinedKeyword = 136,
|
||||
FromKeyword = 137,
|
||||
GlobalKeyword = 138,
|
||||
OfKeyword = 139,
|
||||
QualifiedName = 140,
|
||||
ComputedPropertyName = 141,
|
||||
TypeParameter = 142,
|
||||
Parameter = 143,
|
||||
Decorator = 144,
|
||||
PropertySignature = 145,
|
||||
PropertyDeclaration = 146,
|
||||
MethodSignature = 147,
|
||||
MethodDeclaration = 148,
|
||||
Constructor = 149,
|
||||
GetAccessor = 150,
|
||||
SetAccessor = 151,
|
||||
CallSignature = 152,
|
||||
ConstructSignature = 153,
|
||||
IndexSignature = 154,
|
||||
TypePredicate = 155,
|
||||
TypeReference = 156,
|
||||
FunctionType = 157,
|
||||
ConstructorType = 158,
|
||||
TypeQuery = 159,
|
||||
TypeLiteral = 160,
|
||||
ArrayType = 161,
|
||||
TupleType = 162,
|
||||
UnionType = 163,
|
||||
IntersectionType = 164,
|
||||
ParenthesizedType = 165,
|
||||
ThisType = 166,
|
||||
LiteralType = 167,
|
||||
ObjectBindingPattern = 168,
|
||||
ArrayBindingPattern = 169,
|
||||
BindingElement = 170,
|
||||
ArrayLiteralExpression = 171,
|
||||
ObjectLiteralExpression = 172,
|
||||
PropertyAccessExpression = 173,
|
||||
ElementAccessExpression = 174,
|
||||
CallExpression = 175,
|
||||
NewExpression = 176,
|
||||
TaggedTemplateExpression = 177,
|
||||
TypeAssertionExpression = 178,
|
||||
ParenthesizedExpression = 179,
|
||||
FunctionExpression = 180,
|
||||
ArrowFunction = 181,
|
||||
DeleteExpression = 182,
|
||||
TypeOfExpression = 183,
|
||||
VoidExpression = 184,
|
||||
AwaitExpression = 185,
|
||||
PrefixUnaryExpression = 186,
|
||||
PostfixUnaryExpression = 187,
|
||||
BinaryExpression = 188,
|
||||
ConditionalExpression = 189,
|
||||
TemplateExpression = 190,
|
||||
YieldExpression = 191,
|
||||
SpreadElementExpression = 192,
|
||||
ClassExpression = 193,
|
||||
OmittedExpression = 194,
|
||||
ExpressionWithTypeArguments = 195,
|
||||
AsExpression = 196,
|
||||
NonNullExpression = 197,
|
||||
TemplateSpan = 198,
|
||||
SemicolonClassElement = 199,
|
||||
Block = 200,
|
||||
VariableStatement = 201,
|
||||
EmptyStatement = 202,
|
||||
ExpressionStatement = 203,
|
||||
IfStatement = 204,
|
||||
DoStatement = 205,
|
||||
WhileStatement = 206,
|
||||
ForStatement = 207,
|
||||
ForInStatement = 208,
|
||||
ForOfStatement = 209,
|
||||
ContinueStatement = 210,
|
||||
BreakStatement = 211,
|
||||
ReturnStatement = 212,
|
||||
WithStatement = 213,
|
||||
SwitchStatement = 214,
|
||||
LabeledStatement = 215,
|
||||
ThrowStatement = 216,
|
||||
TryStatement = 217,
|
||||
DebuggerStatement = 218,
|
||||
VariableDeclaration = 219,
|
||||
VariableDeclarationList = 220,
|
||||
FunctionDeclaration = 221,
|
||||
ClassDeclaration = 222,
|
||||
InterfaceDeclaration = 223,
|
||||
TypeAliasDeclaration = 224,
|
||||
EnumDeclaration = 225,
|
||||
ModuleDeclaration = 226,
|
||||
ModuleBlock = 227,
|
||||
CaseBlock = 228,
|
||||
NamespaceExportDeclaration = 229,
|
||||
ImportEqualsDeclaration = 230,
|
||||
ImportDeclaration = 231,
|
||||
ImportClause = 232,
|
||||
NamespaceImport = 233,
|
||||
NamedImports = 234,
|
||||
ImportSpecifier = 235,
|
||||
ExportAssignment = 236,
|
||||
ExportDeclaration = 237,
|
||||
NamedExports = 238,
|
||||
ExportSpecifier = 239,
|
||||
MissingDeclaration = 240,
|
||||
ExternalModuleReference = 241,
|
||||
JsxElement = 242,
|
||||
JsxSelfClosingElement = 243,
|
||||
JsxOpeningElement = 244,
|
||||
JsxClosingElement = 245,
|
||||
JsxAttribute = 246,
|
||||
JsxSpreadAttribute = 247,
|
||||
JsxExpression = 248,
|
||||
CaseClause = 249,
|
||||
DefaultClause = 250,
|
||||
HeritageClause = 251,
|
||||
CatchClause = 252,
|
||||
PropertyAssignment = 253,
|
||||
ShorthandPropertyAssignment = 254,
|
||||
EnumMember = 255,
|
||||
SourceFile = 256,
|
||||
JSDocTypeExpression = 257,
|
||||
JSDocAllType = 258,
|
||||
JSDocUnknownType = 259,
|
||||
JSDocArrayType = 260,
|
||||
JSDocUnionType = 261,
|
||||
JSDocTupleType = 262,
|
||||
JSDocNullableType = 263,
|
||||
JSDocNonNullableType = 264,
|
||||
JSDocRecordType = 265,
|
||||
JSDocRecordMember = 266,
|
||||
JSDocTypeReference = 267,
|
||||
JSDocOptionalType = 268,
|
||||
JSDocFunctionType = 269,
|
||||
JSDocVariadicType = 270,
|
||||
JSDocConstructorType = 271,
|
||||
JSDocThisType = 272,
|
||||
JSDocComment = 273,
|
||||
JSDocTag = 274,
|
||||
JSDocParameterTag = 275,
|
||||
JSDocReturnTag = 276,
|
||||
JSDocTypeTag = 277,
|
||||
JSDocTemplateTag = 278,
|
||||
JSDocTypedefTag = 279,
|
||||
JSDocPropertyTag = 280,
|
||||
JSDocTypeLiteral = 281,
|
||||
JSDocLiteralType = 282,
|
||||
JSDocNullKeyword = 283,
|
||||
JSDocUndefinedKeyword = 284,
|
||||
JSDocNeverKeyword = 285,
|
||||
SyntaxList = 286,
|
||||
NotEmittedStatement = 287,
|
||||
PartiallyEmittedExpression = 288,
|
||||
Count = 289,
|
||||
KeyOfKeyword = 126,
|
||||
ModuleKeyword = 127,
|
||||
NamespaceKeyword = 128,
|
||||
NeverKeyword = 129,
|
||||
ReadonlyKeyword = 130,
|
||||
RequireKeyword = 131,
|
||||
NumberKeyword = 132,
|
||||
SetKeyword = 133,
|
||||
StringKeyword = 134,
|
||||
SymbolKeyword = 135,
|
||||
TypeKeyword = 136,
|
||||
UndefinedKeyword = 137,
|
||||
FromKeyword = 138,
|
||||
GlobalKeyword = 139,
|
||||
OfKeyword = 140,
|
||||
QualifiedName = 141,
|
||||
ComputedPropertyName = 142,
|
||||
TypeParameter = 143,
|
||||
Parameter = 144,
|
||||
Decorator = 145,
|
||||
PropertySignature = 146,
|
||||
PropertyDeclaration = 147,
|
||||
MethodSignature = 148,
|
||||
MethodDeclaration = 149,
|
||||
Constructor = 150,
|
||||
GetAccessor = 151,
|
||||
SetAccessor = 152,
|
||||
CallSignature = 153,
|
||||
ConstructSignature = 154,
|
||||
IndexSignature = 155,
|
||||
TypePredicate = 156,
|
||||
TypeReference = 157,
|
||||
FunctionType = 158,
|
||||
ConstructorType = 159,
|
||||
TypeQuery = 160,
|
||||
TypeLiteral = 161,
|
||||
ArrayType = 162,
|
||||
TupleType = 163,
|
||||
UnionType = 164,
|
||||
IntersectionType = 165,
|
||||
ParenthesizedType = 166,
|
||||
ThisType = 167,
|
||||
TypeOperator = 168,
|
||||
IndexedAccessType = 169,
|
||||
MappedType = 170,
|
||||
LiteralType = 171,
|
||||
ObjectBindingPattern = 172,
|
||||
ArrayBindingPattern = 173,
|
||||
BindingElement = 174,
|
||||
ArrayLiteralExpression = 175,
|
||||
ObjectLiteralExpression = 176,
|
||||
PropertyAccessExpression = 177,
|
||||
ElementAccessExpression = 178,
|
||||
CallExpression = 179,
|
||||
NewExpression = 180,
|
||||
TaggedTemplateExpression = 181,
|
||||
TypeAssertionExpression = 182,
|
||||
ParenthesizedExpression = 183,
|
||||
FunctionExpression = 184,
|
||||
ArrowFunction = 185,
|
||||
DeleteExpression = 186,
|
||||
TypeOfExpression = 187,
|
||||
VoidExpression = 188,
|
||||
AwaitExpression = 189,
|
||||
PrefixUnaryExpression = 190,
|
||||
PostfixUnaryExpression = 191,
|
||||
BinaryExpression = 192,
|
||||
ConditionalExpression = 193,
|
||||
TemplateExpression = 194,
|
||||
YieldExpression = 195,
|
||||
SpreadElement = 196,
|
||||
ClassExpression = 197,
|
||||
OmittedExpression = 198,
|
||||
ExpressionWithTypeArguments = 199,
|
||||
AsExpression = 200,
|
||||
NonNullExpression = 201,
|
||||
TemplateSpan = 202,
|
||||
SemicolonClassElement = 203,
|
||||
Block = 204,
|
||||
VariableStatement = 205,
|
||||
EmptyStatement = 206,
|
||||
ExpressionStatement = 207,
|
||||
IfStatement = 208,
|
||||
DoStatement = 209,
|
||||
WhileStatement = 210,
|
||||
ForStatement = 211,
|
||||
ForInStatement = 212,
|
||||
ForOfStatement = 213,
|
||||
ContinueStatement = 214,
|
||||
BreakStatement = 215,
|
||||
ReturnStatement = 216,
|
||||
WithStatement = 217,
|
||||
SwitchStatement = 218,
|
||||
LabeledStatement = 219,
|
||||
ThrowStatement = 220,
|
||||
TryStatement = 221,
|
||||
DebuggerStatement = 222,
|
||||
VariableDeclaration = 223,
|
||||
VariableDeclarationList = 224,
|
||||
FunctionDeclaration = 225,
|
||||
ClassDeclaration = 226,
|
||||
InterfaceDeclaration = 227,
|
||||
TypeAliasDeclaration = 228,
|
||||
EnumDeclaration = 229,
|
||||
ModuleDeclaration = 230,
|
||||
ModuleBlock = 231,
|
||||
CaseBlock = 232,
|
||||
NamespaceExportDeclaration = 233,
|
||||
ImportEqualsDeclaration = 234,
|
||||
ImportDeclaration = 235,
|
||||
ImportClause = 236,
|
||||
NamespaceImport = 237,
|
||||
NamedImports = 238,
|
||||
ImportSpecifier = 239,
|
||||
ExportAssignment = 240,
|
||||
ExportDeclaration = 241,
|
||||
NamedExports = 242,
|
||||
ExportSpecifier = 243,
|
||||
MissingDeclaration = 244,
|
||||
ExternalModuleReference = 245,
|
||||
JsxElement = 246,
|
||||
JsxSelfClosingElement = 247,
|
||||
JsxOpeningElement = 248,
|
||||
JsxClosingElement = 249,
|
||||
JsxAttribute = 250,
|
||||
JsxSpreadAttribute = 251,
|
||||
JsxExpression = 252,
|
||||
CaseClause = 253,
|
||||
DefaultClause = 254,
|
||||
HeritageClause = 255,
|
||||
CatchClause = 256,
|
||||
PropertyAssignment = 257,
|
||||
ShorthandPropertyAssignment = 258,
|
||||
SpreadAssignment = 259,
|
||||
EnumMember = 260,
|
||||
SourceFile = 261,
|
||||
JSDocTypeExpression = 262,
|
||||
JSDocAllType = 263,
|
||||
JSDocUnknownType = 264,
|
||||
JSDocArrayType = 265,
|
||||
JSDocUnionType = 266,
|
||||
JSDocTupleType = 267,
|
||||
JSDocNullableType = 268,
|
||||
JSDocNonNullableType = 269,
|
||||
JSDocRecordType = 270,
|
||||
JSDocRecordMember = 271,
|
||||
JSDocTypeReference = 272,
|
||||
JSDocOptionalType = 273,
|
||||
JSDocFunctionType = 274,
|
||||
JSDocVariadicType = 275,
|
||||
JSDocConstructorType = 276,
|
||||
JSDocThisType = 277,
|
||||
JSDocComment = 278,
|
||||
JSDocTag = 279,
|
||||
JSDocParameterTag = 280,
|
||||
JSDocReturnTag = 281,
|
||||
JSDocTypeTag = 282,
|
||||
JSDocTemplateTag = 283,
|
||||
JSDocTypedefTag = 284,
|
||||
JSDocPropertyTag = 285,
|
||||
JSDocTypeLiteral = 286,
|
||||
JSDocLiteralType = 287,
|
||||
JSDocNullKeyword = 288,
|
||||
JSDocUndefinedKeyword = 289,
|
||||
JSDocNeverKeyword = 290,
|
||||
SyntaxList = 291,
|
||||
NotEmittedStatement = 292,
|
||||
PartiallyEmittedExpression = 293,
|
||||
MergeDeclarationMarker = 294,
|
||||
EndOfDeclarationMarker = 295,
|
||||
Count = 296,
|
||||
FirstAssignment = 57,
|
||||
LastAssignment = 69,
|
||||
FirstCompoundAssignment = 58,
|
||||
@@ -334,15 +341,15 @@ declare namespace ts {
|
||||
FirstReservedWord = 71,
|
||||
LastReservedWord = 106,
|
||||
FirstKeyword = 71,
|
||||
LastKeyword = 139,
|
||||
LastKeyword = 140,
|
||||
FirstFutureReservedWord = 107,
|
||||
LastFutureReservedWord = 115,
|
||||
FirstTypeNode = 155,
|
||||
LastTypeNode = 167,
|
||||
FirstTypeNode = 156,
|
||||
LastTypeNode = 171,
|
||||
FirstPunctuation = 16,
|
||||
LastPunctuation = 69,
|
||||
FirstToken = 0,
|
||||
LastToken = 139,
|
||||
LastToken = 140,
|
||||
FirstTriviaToken = 2,
|
||||
LastTriviaToken = 7,
|
||||
FirstLiteralToken = 8,
|
||||
@@ -351,11 +358,11 @@ declare namespace ts {
|
||||
LastTemplateToken = 15,
|
||||
FirstBinaryOperator = 26,
|
||||
LastBinaryOperator = 69,
|
||||
FirstNode = 140,
|
||||
FirstJSDocNode = 257,
|
||||
LastJSDocNode = 282,
|
||||
FirstJSDocTagNode = 273,
|
||||
LastJSDocTagNode = 285,
|
||||
FirstNode = 141,
|
||||
FirstJSDocNode = 262,
|
||||
LastJSDocNode = 287,
|
||||
FirstJSDocTagNode = 278,
|
||||
LastJSDocTagNode = 290,
|
||||
}
|
||||
enum NodeFlags {
|
||||
None = 0,
|
||||
@@ -373,21 +380,22 @@ declare namespace ts {
|
||||
HasDecorators = 2048,
|
||||
HasParamDecorators = 4096,
|
||||
HasAsyncFunctions = 8192,
|
||||
HasJsxSpreadAttributes = 16384,
|
||||
DisallowInContext = 32768,
|
||||
YieldContext = 65536,
|
||||
DecoratorContext = 131072,
|
||||
AwaitContext = 262144,
|
||||
ThisNodeHasError = 524288,
|
||||
JavaScriptFile = 1048576,
|
||||
ThisNodeOrAnySubNodesHasError = 2097152,
|
||||
HasAggregatedChildData = 4194304,
|
||||
HasSpreadAttribute = 16384,
|
||||
HasRestAttribute = 32768,
|
||||
DisallowInContext = 65536,
|
||||
YieldContext = 131072,
|
||||
DecoratorContext = 262144,
|
||||
AwaitContext = 524288,
|
||||
ThisNodeHasError = 1048576,
|
||||
JavaScriptFile = 2097152,
|
||||
ThisNodeOrAnySubNodesHasError = 4194304,
|
||||
HasAggregatedChildData = 8388608,
|
||||
BlockScoped = 3,
|
||||
ReachabilityCheckFlags = 384,
|
||||
EmitHelperFlags = 31744,
|
||||
ReachabilityAndEmitFlags = 32128,
|
||||
ContextFlags = 1540096,
|
||||
TypeExcludesFlags = 327680,
|
||||
EmitHelperFlags = 64512,
|
||||
ReachabilityAndEmitFlags = 64896,
|
||||
ContextFlags = 3080192,
|
||||
TypeExcludesFlags = 655360,
|
||||
}
|
||||
enum ModifierFlags {
|
||||
None = 0,
|
||||
@@ -407,6 +415,7 @@ declare namespace ts {
|
||||
ParameterPropertyModifier = 92,
|
||||
NonPublicAccessibilityModifier = 24,
|
||||
TypeScriptModifier = 2270,
|
||||
ExportDefault = 513,
|
||||
}
|
||||
enum JsxFlags {
|
||||
None = 0,
|
||||
@@ -437,12 +446,14 @@ declare namespace ts {
|
||||
type EqualsGreaterThanToken = Token<SyntaxKind.EqualsGreaterThanToken>;
|
||||
type EndOfFileToken = Token<SyntaxKind.EndOfFileToken>;
|
||||
type AtToken = Token<SyntaxKind.AtToken>;
|
||||
type ReadonlyToken = Token<SyntaxKind.ReadonlyKeyword>;
|
||||
type Modifier = Token<SyntaxKind.AbstractKeyword> | Token<SyntaxKind.AsyncKeyword> | Token<SyntaxKind.ConstKeyword> | Token<SyntaxKind.DeclareKeyword> | Token<SyntaxKind.DefaultKeyword> | Token<SyntaxKind.ExportKeyword> | Token<SyntaxKind.PublicKeyword> | Token<SyntaxKind.PrivateKeyword> | Token<SyntaxKind.ProtectedKeyword> | Token<SyntaxKind.ReadonlyKeyword> | Token<SyntaxKind.StaticKeyword>;
|
||||
type ModifiersArray = NodeArray<Modifier>;
|
||||
interface Identifier extends PrimaryExpression {
|
||||
kind: SyntaxKind.Identifier;
|
||||
text: string;
|
||||
originalKeywordKind?: SyntaxKind;
|
||||
isInJSDocNamespace?: boolean;
|
||||
}
|
||||
interface TransientIdentifier extends Identifier {
|
||||
resolvedSymbol: Symbol;
|
||||
@@ -533,7 +544,7 @@ declare namespace ts {
|
||||
_objectLiteralBrandBrand: any;
|
||||
name?: PropertyName;
|
||||
}
|
||||
type ObjectLiteralElementLike = PropertyAssignment | ShorthandPropertyAssignment | MethodDeclaration | AccessorDeclaration;
|
||||
type ObjectLiteralElementLike = PropertyAssignment | ShorthandPropertyAssignment | MethodDeclaration | AccessorDeclaration | SpreadAssignment;
|
||||
interface PropertyAssignment extends ObjectLiteralElement {
|
||||
kind: SyntaxKind.PropertyAssignment;
|
||||
name: PropertyName;
|
||||
@@ -547,6 +558,10 @@ declare namespace ts {
|
||||
equalsToken?: Token<SyntaxKind.EqualsToken>;
|
||||
objectAssignmentInitializer?: Expression;
|
||||
}
|
||||
interface SpreadAssignment extends ObjectLiteralElement {
|
||||
kind: SyntaxKind.SpreadAssignment;
|
||||
expression: Expression;
|
||||
}
|
||||
interface VariableLikeDeclaration extends Declaration {
|
||||
propertyName?: PropertyName;
|
||||
dotDotDotToken?: DotDotDotToken;
|
||||
@@ -677,6 +692,23 @@ declare namespace ts {
|
||||
kind: SyntaxKind.ParenthesizedType;
|
||||
type: TypeNode;
|
||||
}
|
||||
interface TypeOperatorNode extends TypeNode {
|
||||
kind: SyntaxKind.TypeOperator;
|
||||
operator: SyntaxKind.KeyOfKeyword;
|
||||
type: TypeNode;
|
||||
}
|
||||
interface IndexedAccessTypeNode extends TypeNode {
|
||||
kind: SyntaxKind.IndexedAccessType;
|
||||
objectType: TypeNode;
|
||||
indexType: TypeNode;
|
||||
}
|
||||
interface MappedTypeNode extends TypeNode, Declaration {
|
||||
kind: SyntaxKind.MappedType;
|
||||
readonlyToken?: ReadonlyToken;
|
||||
typeParameter: TypeParameterDeclaration;
|
||||
questionToken?: QuestionToken;
|
||||
type?: TypeNode;
|
||||
}
|
||||
interface LiteralTypeNode extends TypeNode {
|
||||
kind: SyntaxKind.LiteralType;
|
||||
literal: Expression;
|
||||
@@ -709,9 +741,6 @@ declare namespace ts {
|
||||
operand: LeftHandSideExpression;
|
||||
operator: PostfixUnaryOperator;
|
||||
}
|
||||
interface PostfixExpression extends UnaryExpression {
|
||||
_postfixExpressionBrand: any;
|
||||
}
|
||||
interface LeftHandSideExpression extends IncrementExpression {
|
||||
_leftHandSideExpressionBrand: any;
|
||||
}
|
||||
@@ -780,6 +809,17 @@ declare namespace ts {
|
||||
operatorToken: BinaryOperatorToken;
|
||||
right: Expression;
|
||||
}
|
||||
interface AssignmentExpression extends BinaryExpression {
|
||||
left: LeftHandSideExpression;
|
||||
operatorToken: Token<SyntaxKind.EqualsToken>;
|
||||
}
|
||||
interface ObjectDestructuringAssignment extends AssignmentExpression {
|
||||
left: ObjectLiteralExpression;
|
||||
}
|
||||
interface ArrayDestructuringAssignment extends AssignmentExpression {
|
||||
left: ArrayLiteralExpression;
|
||||
}
|
||||
type DestructuringAssignment = ObjectDestructuringAssignment | ArrayDestructuringAssignment;
|
||||
interface ConditionalExpression extends Expression {
|
||||
kind: SyntaxKind.ConditionalExpression;
|
||||
condition: Expression;
|
||||
@@ -846,8 +886,8 @@ declare namespace ts {
|
||||
kind: SyntaxKind.ArrayLiteralExpression;
|
||||
elements: NodeArray<Expression>;
|
||||
}
|
||||
interface SpreadElementExpression extends Expression {
|
||||
kind: SyntaxKind.SpreadElementExpression;
|
||||
interface SpreadElement extends Expression {
|
||||
kind: SyntaxKind.SpreadElement;
|
||||
expression: Expression;
|
||||
}
|
||||
/**
|
||||
@@ -1141,12 +1181,16 @@ declare namespace ts {
|
||||
interface ModuleDeclaration extends DeclarationStatement {
|
||||
kind: SyntaxKind.ModuleDeclaration;
|
||||
name: Identifier | LiteralExpression;
|
||||
body?: ModuleBlock | NamespaceDeclaration;
|
||||
body?: ModuleBlock | NamespaceDeclaration | JSDocNamespaceDeclaration | Identifier;
|
||||
}
|
||||
interface NamespaceDeclaration extends ModuleDeclaration {
|
||||
name: Identifier;
|
||||
body: ModuleBlock | NamespaceDeclaration;
|
||||
}
|
||||
interface JSDocNamespaceDeclaration extends ModuleDeclaration {
|
||||
name: Identifier;
|
||||
body: JSDocNamespaceDeclaration | Identifier;
|
||||
}
|
||||
interface ModuleBlock extends Node, Statement {
|
||||
kind: SyntaxKind.ModuleBlock;
|
||||
statements: NodeArray<Statement>;
|
||||
@@ -1318,6 +1362,7 @@ declare namespace ts {
|
||||
}
|
||||
interface JSDocTypedefTag extends JSDocTag, Declaration {
|
||||
kind: SyntaxKind.JSDocTypedefTag;
|
||||
fullName?: JSDocNamespaceDeclaration | Identifier;
|
||||
name?: Identifier;
|
||||
typeExpression?: JSDocTypeExpression;
|
||||
jsDocTypeLiteral?: JSDocTypeLiteral;
|
||||
@@ -1708,14 +1753,11 @@ declare namespace ts {
|
||||
Null = 4096,
|
||||
Never = 8192,
|
||||
TypeParameter = 16384,
|
||||
Class = 32768,
|
||||
Interface = 65536,
|
||||
Reference = 131072,
|
||||
Tuple = 262144,
|
||||
Union = 524288,
|
||||
Intersection = 1048576,
|
||||
Anonymous = 2097152,
|
||||
Instantiated = 4194304,
|
||||
Object = 32768,
|
||||
Union = 65536,
|
||||
Intersection = 131072,
|
||||
Index = 262144,
|
||||
IndexedAccess = 524288,
|
||||
Literal = 480,
|
||||
StringOrNumberLiteral = 96,
|
||||
PossiblyFalsy = 7406,
|
||||
@@ -1723,12 +1765,11 @@ declare namespace ts {
|
||||
NumberLike = 340,
|
||||
BooleanLike = 136,
|
||||
EnumLike = 272,
|
||||
ObjectType = 2588672,
|
||||
UnionOrIntersection = 1572864,
|
||||
StructuredType = 4161536,
|
||||
StructuredOrTypeParameter = 4177920,
|
||||
Narrowable = 4178943,
|
||||
NotUnionOrUnit = 2589185,
|
||||
UnionOrIntersection = 196608,
|
||||
StructuredType = 229376,
|
||||
StructuredOrTypeParameter = 507904,
|
||||
Narrowable = 1033215,
|
||||
NotUnionOrUnit = 33281,
|
||||
}
|
||||
type DestructuringPattern = BindingPattern | ObjectLiteralExpression | ArrayLiteralExpression;
|
||||
interface Type {
|
||||
@@ -1749,8 +1790,21 @@ declare namespace ts {
|
||||
interface EnumLiteralType extends LiteralType {
|
||||
baseType: EnumType & UnionType;
|
||||
}
|
||||
enum ObjectFlags {
|
||||
Class = 1,
|
||||
Interface = 2,
|
||||
Reference = 4,
|
||||
Tuple = 8,
|
||||
Anonymous = 16,
|
||||
Mapped = 32,
|
||||
Instantiated = 64,
|
||||
ObjectLiteral = 128,
|
||||
EvolvingArray = 256,
|
||||
ObjectLiteralPatternWithComputedProperties = 512,
|
||||
ClassOrInterface = 3,
|
||||
}
|
||||
interface ObjectType extends Type {
|
||||
isObjectLiteralPatternWithComputedProperties?: boolean;
|
||||
objectFlags: ObjectFlags;
|
||||
}
|
||||
interface InterfaceType extends ObjectType {
|
||||
typeParameters: TypeParameter[];
|
||||
@@ -1778,9 +1832,21 @@ declare namespace ts {
|
||||
}
|
||||
interface IntersectionType extends UnionOrIntersectionType {
|
||||
}
|
||||
type StructuredType = ObjectType | UnionType | IntersectionType;
|
||||
interface EvolvingArrayType extends ObjectType {
|
||||
elementType: Type;
|
||||
finalArrayType?: Type;
|
||||
}
|
||||
interface TypeParameter extends Type {
|
||||
constraint: Type;
|
||||
}
|
||||
interface IndexType extends Type {
|
||||
type: TypeParameter;
|
||||
}
|
||||
interface IndexedAccessType extends Type {
|
||||
objectType: Type;
|
||||
indexType: TypeParameter;
|
||||
}
|
||||
enum SignatureKind {
|
||||
Call = 0,
|
||||
Construct = 1,
|
||||
@@ -1882,6 +1948,7 @@ declare namespace ts {
|
||||
preserveConstEnums?: boolean;
|
||||
project?: string;
|
||||
reactNamespace?: string;
|
||||
jsxFactory?: string;
|
||||
removeComments?: boolean;
|
||||
rootDir?: string;
|
||||
rootDirs?: string[];
|
||||
@@ -1912,6 +1979,7 @@ declare namespace ts {
|
||||
packageNameToTypingLocation: Map<string>;
|
||||
typingOptions: TypingOptions;
|
||||
compilerOptions: CompilerOptions;
|
||||
unresolvedImports: ReadonlyArray<string>;
|
||||
}
|
||||
enum ModuleKind {
|
||||
None = 0,
|
||||
@@ -1947,12 +2015,14 @@ declare namespace ts {
|
||||
ES2015 = 2,
|
||||
ES2016 = 3,
|
||||
ES2017 = 4,
|
||||
Latest = 4,
|
||||
ESNext = 5,
|
||||
Latest = 5,
|
||||
}
|
||||
enum LanguageVariant {
|
||||
Standard = 0,
|
||||
JSX = 1,
|
||||
}
|
||||
/** Either a parsed command line or a parsed tsconfig.json */
|
||||
interface ParsedCommandLine {
|
||||
options: CompilerOptions;
|
||||
typingOptions?: TypingOptions;
|
||||
@@ -1979,12 +2049,45 @@ declare namespace ts {
|
||||
getCurrentDirectory?(): string;
|
||||
getDirectories?(path: string): string[];
|
||||
}
|
||||
/**
|
||||
* Represents the result of module resolution.
|
||||
* Module resolution will pick up tsx/jsx/js files even if '--jsx' and '--allowJs' are turned off.
|
||||
* The Program will then filter results based on these flags.
|
||||
*
|
||||
* Prefer to return a `ResolvedModuleFull` so that the file type does not have to be inferred.
|
||||
*/
|
||||
interface ResolvedModule {
|
||||
/** Path of the file the module was resolved to. */
|
||||
resolvedFileName: string;
|
||||
/**
|
||||
* Denotes if 'resolvedFileName' is isExternalLibraryImport and thus should be a proper external module:
|
||||
* - be a .d.ts file
|
||||
* - use top level imports\exports
|
||||
* - don't use tripleslash references
|
||||
*/
|
||||
isExternalLibraryImport?: boolean;
|
||||
}
|
||||
/**
|
||||
* ResolvedModule with an explicitly provided `extension` property.
|
||||
* Prefer this over `ResolvedModule`.
|
||||
*/
|
||||
interface ResolvedModuleFull extends ResolvedModule {
|
||||
/**
|
||||
* Extension of resolvedFileName. This must match what's at the end of resolvedFileName.
|
||||
* This is optional for backwards-compatibility, but will be added if not provided.
|
||||
*/
|
||||
extension: Extension;
|
||||
}
|
||||
enum Extension {
|
||||
Ts = 0,
|
||||
Tsx = 1,
|
||||
Dts = 2,
|
||||
Js = 3,
|
||||
Jsx = 4,
|
||||
LastTypeScriptExtension = 2,
|
||||
}
|
||||
interface ResolvedModuleWithFailedLookupLocations {
|
||||
resolvedModule: ResolvedModule;
|
||||
resolvedModule: ResolvedModuleFull | undefined;
|
||||
failedLookupLocations: string[];
|
||||
}
|
||||
interface ResolvedTypeReferenceDirective {
|
||||
@@ -2042,7 +2145,11 @@ declare namespace ts {
|
||||
readFile(path: string, encoding?: string): string;
|
||||
getFileSize?(path: string): number;
|
||||
writeFile(path: string, data: string, writeByteOrderMark?: boolean): void;
|
||||
watchFile?(path: string, callback: FileWatcherCallback): FileWatcher;
|
||||
/**
|
||||
* @pollingInterval - this parameter is used in polling-based watchers and ignored in watchers that
|
||||
* use native OS file watching
|
||||
*/
|
||||
watchFile?(path: string, callback: FileWatcherCallback, pollingInterval?: number): FileWatcher;
|
||||
watchDirectory?(path: string, callback: DirectoryWatcherCallback, recursive?: boolean): FileWatcher;
|
||||
resolvePath(path: string): string;
|
||||
fileExists(path: string): boolean;
|
||||
@@ -2057,6 +2164,8 @@ declare namespace ts {
|
||||
getMemoryUsage?(): number;
|
||||
exit(exitCode?: number): void;
|
||||
realpath?(path: string): string;
|
||||
setTimeout?(callback: (...args: any[]) => void, ms: number, ...args: any[]): any;
|
||||
clearTimeout?(timeoutId: any): void;
|
||||
}
|
||||
interface FileWatcher {
|
||||
close(): void;
|
||||
@@ -2159,6 +2268,7 @@ declare namespace ts {
|
||||
function createNode(kind: SyntaxKind, pos?: number, end?: number): Node;
|
||||
function forEachChild<T>(node: Node, cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T;
|
||||
function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean, scriptKind?: ScriptKind): SourceFile;
|
||||
function parseIsolatedEntityName(text: string, languageVersion: ScriptTarget): EntityName;
|
||||
function isExternalModule(file: SourceFile): boolean;
|
||||
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;
|
||||
}
|
||||
@@ -2172,7 +2282,7 @@ declare namespace ts {
|
||||
* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups
|
||||
* is assumed to be the same as root directory of the project.
|
||||
*/
|
||||
function resolveTypeReferenceDirective(typeReferenceDirectiveName: string, containingFile: string, options: CompilerOptions, host: ModuleResolutionHost): ResolvedTypeReferenceDirectiveWithFailedLookupLocations;
|
||||
function resolveTypeReferenceDirective(typeReferenceDirectiveName: string, containingFile: string | undefined, options: CompilerOptions, host: ModuleResolutionHost): ResolvedTypeReferenceDirectiveWithFailedLookupLocations;
|
||||
/**
|
||||
* Given a set of options, returns the set of type directive names
|
||||
* that should be included for this program automatically.
|
||||
@@ -2188,7 +2298,7 @@ declare namespace ts {
|
||||
}
|
||||
declare namespace ts {
|
||||
/** The version of the TypeScript compiler release */
|
||||
const version = "2.1.0";
|
||||
const version = "2.2.0";
|
||||
function findConfigFile(searchPath: string, fileExists: (fileName: string) => boolean, configName?: string): string;
|
||||
function resolveTripleslashReference(moduleName: string, containingFile: string): string;
|
||||
function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost;
|
||||
|
||||
+11985
-9262
File diff suppressed because it is too large
Load Diff
+757
-1381
File diff suppressed because it is too large
Load Diff
+2
-3
@@ -2,7 +2,7 @@
|
||||
"name": "typescript",
|
||||
"author": "Microsoft Corp.",
|
||||
"homepage": "http://typescriptlang.org/",
|
||||
"version": "2.1.0",
|
||||
"version": "2.2.0",
|
||||
"license": "Apache-2.0",
|
||||
"description": "TypeScript is a language for application scale JavaScript development",
|
||||
"keywords": [
|
||||
@@ -75,8 +75,7 @@
|
||||
"through2": "latest",
|
||||
"travis-fold": "latest",
|
||||
"ts-node": "latest",
|
||||
"tsd": "latest",
|
||||
"tslint": "4.0.0-dev.0",
|
||||
"tslint": "next",
|
||||
"typescript": "next"
|
||||
},
|
||||
"scripts": {
|
||||
|
||||
+161
-61
@@ -234,8 +234,8 @@ namespace ts {
|
||||
if (node.name.kind === SyntaxKind.ComputedPropertyName) {
|
||||
const nameExpression = (<ComputedPropertyName>node.name).expression;
|
||||
// treat computed property names where expression is string/numeric literal as just string/numeric literal
|
||||
if (isStringOrNumericLiteral(nameExpression.kind)) {
|
||||
return (<LiteralExpression>nameExpression).text;
|
||||
if (isStringOrNumericLiteral(nameExpression)) {
|
||||
return nameExpression.text;
|
||||
}
|
||||
|
||||
Debug.assert(isWellKnownSymbolSyntactically(nameExpression));
|
||||
@@ -570,6 +570,31 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function bindEach(nodes: NodeArray<Node>) {
|
||||
if (nodes === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (skipTransformFlagAggregation) {
|
||||
forEach(nodes, bind);
|
||||
}
|
||||
else {
|
||||
const savedSubtreeTransformFlags = subtreeTransformFlags;
|
||||
subtreeTransformFlags = TransformFlags.None;
|
||||
let nodeArrayFlags = TransformFlags.None;
|
||||
for (const node of nodes) {
|
||||
bind(node);
|
||||
nodeArrayFlags |= node.transformFlags & ~TransformFlags.HasComputedFlags;
|
||||
}
|
||||
nodes.transformFlags = nodeArrayFlags | TransformFlags.HasComputedFlags;
|
||||
subtreeTransformFlags |= savedSubtreeTransformFlags;
|
||||
}
|
||||
}
|
||||
|
||||
function bindEachChild(node: Node) {
|
||||
forEachChild(node, bind, bindEach);
|
||||
}
|
||||
|
||||
function bindChildrenWorker(node: Node): void {
|
||||
// Binding of JsDocComment should be done before the current block scope container changes.
|
||||
// because the scope of JsDocComment should not be affected by whether the current node is a
|
||||
@@ -578,7 +603,7 @@ namespace ts {
|
||||
forEach(node.jsDocComments, bind);
|
||||
}
|
||||
if (checkUnreachable(node)) {
|
||||
forEachChild(node, bind);
|
||||
bindEachChild(node);
|
||||
return;
|
||||
}
|
||||
switch (node.kind) {
|
||||
@@ -643,7 +668,7 @@ namespace ts {
|
||||
bindCallExpressionFlow(<CallExpression>node);
|
||||
break;
|
||||
default:
|
||||
forEachChild(node, bind);
|
||||
bindEachChild(node);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -979,7 +1004,7 @@ namespace ts {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function bindbreakOrContinueFlow(node: BreakOrContinueStatement, breakTarget: FlowLabel, continueTarget: FlowLabel) {
|
||||
function bindBreakOrContinueFlow(node: BreakOrContinueStatement, breakTarget: FlowLabel, continueTarget: FlowLabel) {
|
||||
const flowLabel = node.kind === SyntaxKind.BreakStatement ? breakTarget : continueTarget;
|
||||
if (flowLabel) {
|
||||
addAntecedent(flowLabel, currentFlow);
|
||||
@@ -993,11 +1018,11 @@ namespace ts {
|
||||
const activeLabel = findActiveLabel(node.label.text);
|
||||
if (activeLabel) {
|
||||
activeLabel.referenced = true;
|
||||
bindbreakOrContinueFlow(node, activeLabel.breakTarget, activeLabel.continueTarget);
|
||||
bindBreakOrContinueFlow(node, activeLabel.breakTarget, activeLabel.continueTarget);
|
||||
}
|
||||
}
|
||||
else {
|
||||
bindbreakOrContinueFlow(node, currentBreakTarget, currentContinueTarget);
|
||||
bindBreakOrContinueFlow(node, currentBreakTarget, currentContinueTarget);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1065,6 +1090,8 @@ namespace ts {
|
||||
}
|
||||
|
||||
function bindCaseBlock(node: CaseBlock): void {
|
||||
const savedSubtreeTransformFlags = subtreeTransformFlags;
|
||||
subtreeTransformFlags = 0;
|
||||
const clauses = node.clauses;
|
||||
let fallthroughFlow = unreachableFlow;
|
||||
for (let i = 0; i < clauses.length; i++) {
|
||||
@@ -1084,6 +1111,8 @@ namespace ts {
|
||||
errorOnFirstToken(clause, Diagnostics.Fallthrough_case_in_switch);
|
||||
}
|
||||
}
|
||||
clauses.transformFlags = subtreeTransformFlags | TransformFlags.HasComputedFlags;
|
||||
subtreeTransformFlags |= savedSubtreeTransformFlags;
|
||||
}
|
||||
|
||||
function bindCaseClause(node: CaseClause): void {
|
||||
@@ -1091,7 +1120,7 @@ namespace ts {
|
||||
currentFlow = preSwitchCaseFlow;
|
||||
bind(node.expression);
|
||||
currentFlow = saveCurrentFlow;
|
||||
forEach(node.statements, bind);
|
||||
bindEach(node.statements);
|
||||
}
|
||||
|
||||
function pushActiveLabel(name: string, breakTarget: FlowLabel, continueTarget: FlowLabel): ActiveLabel {
|
||||
@@ -1142,8 +1171,8 @@ namespace ts {
|
||||
}
|
||||
else if (node.kind === SyntaxKind.ArrayLiteralExpression) {
|
||||
for (const e of (<ArrayLiteralExpression>node).elements) {
|
||||
if (e.kind === SyntaxKind.SpreadElementExpression) {
|
||||
bindAssignmentTargetFlow((<SpreadElementExpression>e).expression);
|
||||
if (e.kind === SyntaxKind.SpreadElement) {
|
||||
bindAssignmentTargetFlow((<SpreadElement>e).expression);
|
||||
}
|
||||
else {
|
||||
bindDestructuringTargetFlow(e);
|
||||
@@ -1158,6 +1187,9 @@ namespace ts {
|
||||
else if (p.kind === SyntaxKind.ShorthandPropertyAssignment) {
|
||||
bindAssignmentTargetFlow((<ShorthandPropertyAssignment>p).name);
|
||||
}
|
||||
else if (p.kind === SyntaxKind.SpreadAssignment) {
|
||||
bindAssignmentTargetFlow((<SpreadAssignment>p).expression);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1180,12 +1212,12 @@ namespace ts {
|
||||
const saveTrueTarget = currentTrueTarget;
|
||||
currentTrueTarget = currentFalseTarget;
|
||||
currentFalseTarget = saveTrueTarget;
|
||||
forEachChild(node, bind);
|
||||
bindEachChild(node);
|
||||
currentFalseTarget = currentTrueTarget;
|
||||
currentTrueTarget = saveTrueTarget;
|
||||
}
|
||||
else {
|
||||
forEachChild(node, bind);
|
||||
bindEachChild(node);
|
||||
if (node.operator === SyntaxKind.PlusPlusToken || node.operator === SyntaxKind.MinusMinusToken) {
|
||||
bindAssignmentTargetFlow(node.operand);
|
||||
}
|
||||
@@ -1193,7 +1225,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function bindPostfixUnaryExpressionFlow(node: PostfixUnaryExpression) {
|
||||
forEachChild(node, bind);
|
||||
bindEachChild(node);
|
||||
if (node.operator === SyntaxKind.PlusPlusToken || node.operator === SyntaxKind.MinusMinusToken) {
|
||||
bindAssignmentTargetFlow(node.operand);
|
||||
}
|
||||
@@ -1212,7 +1244,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
else {
|
||||
forEachChild(node, bind);
|
||||
bindEachChild(node);
|
||||
if (isAssignmentOperator(operator) && !isAssignmentTarget(node)) {
|
||||
bindAssignmentTargetFlow(node.left);
|
||||
if (operator === SyntaxKind.EqualsToken && node.left.kind === SyntaxKind.ElementAccessExpression) {
|
||||
@@ -1226,7 +1258,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function bindDeleteExpressionFlow(node: DeleteExpression) {
|
||||
forEachChild(node, bind);
|
||||
bindEachChild(node);
|
||||
if (node.expression.kind === SyntaxKind.PropertyAccessExpression) {
|
||||
bindAssignmentTargetFlow(node.expression);
|
||||
}
|
||||
@@ -1251,7 +1283,7 @@ namespace ts {
|
||||
function bindInitializedVariableFlow(node: VariableDeclaration | ArrayBindingElement) {
|
||||
const name = !isOmittedExpression(node) ? node.name : undefined;
|
||||
if (isBindingPattern(name)) {
|
||||
for (const child of name.elements) {
|
||||
for (const child of <ArrayBindingElement[]>name.elements) {
|
||||
bindInitializedVariableFlow(child);
|
||||
}
|
||||
}
|
||||
@@ -1261,7 +1293,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function bindVariableDeclarationFlow(node: VariableDeclaration) {
|
||||
forEachChild(node, bind);
|
||||
bindEachChild(node);
|
||||
if (node.initializer || node.parent.parent.kind === SyntaxKind.ForInStatement || node.parent.parent.kind === SyntaxKind.ForOfStatement) {
|
||||
bindInitializedVariableFlow(node);
|
||||
}
|
||||
@@ -1276,12 +1308,12 @@ namespace ts {
|
||||
expr = (<ParenthesizedExpression>expr).expression;
|
||||
}
|
||||
if (expr.kind === SyntaxKind.FunctionExpression || expr.kind === SyntaxKind.ArrowFunction) {
|
||||
forEach(node.typeArguments, bind);
|
||||
forEach(node.arguments, bind);
|
||||
bindEach(node.typeArguments);
|
||||
bindEach(node.arguments);
|
||||
bind(node.expression);
|
||||
}
|
||||
else {
|
||||
forEachChild(node, bind);
|
||||
bindEachChild(node);
|
||||
}
|
||||
if (node.expression.kind === SyntaxKind.PropertyAccessExpression) {
|
||||
const propertyAccess = <PropertyAccessExpression>node.expression;
|
||||
@@ -1308,6 +1340,7 @@ namespace ts {
|
||||
case SyntaxKind.JSDocFunctionType:
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
case SyntaxKind.TypeAliasDeclaration:
|
||||
case SyntaxKind.MappedType:
|
||||
return ContainerFlags.IsContainer | ContainerFlags.HasLocals;
|
||||
|
||||
case SyntaxKind.SourceFile:
|
||||
@@ -1427,6 +1460,7 @@ namespace ts {
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.JSDocFunctionType:
|
||||
case SyntaxKind.TypeAliasDeclaration:
|
||||
case SyntaxKind.MappedType:
|
||||
// All the children of these container types are never visible through another
|
||||
// symbol (i.e. through another symbol's 'exports' or 'members'). Instead,
|
||||
// they're only accessed 'lexically' (i.e. from code that exists underneath
|
||||
@@ -1553,7 +1587,7 @@ namespace ts {
|
||||
const seen = createMap<ElementKind>();
|
||||
|
||||
for (const prop of node.properties) {
|
||||
if (prop.name.kind !== SyntaxKind.Identifier) {
|
||||
if (prop.kind === SyntaxKind.SpreadAssignment || prop.name.kind !== SyntaxKind.Identifier) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1932,8 +1966,20 @@ namespace ts {
|
||||
case SyntaxKind.EnumMember:
|
||||
return bindPropertyOrMethodOrAccessor(<Declaration>node, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes);
|
||||
|
||||
case SyntaxKind.SpreadAssignment:
|
||||
case SyntaxKind.JsxSpreadAttribute:
|
||||
emitFlags |= NodeFlags.HasJsxSpreadAttributes;
|
||||
let root = container;
|
||||
let hasRest = false;
|
||||
while (root.parent) {
|
||||
if (root.kind === SyntaxKind.ObjectLiteralExpression &&
|
||||
root.parent.kind === SyntaxKind.BinaryExpression &&
|
||||
(root.parent as BinaryExpression).operatorToken.kind === SyntaxKind.EqualsToken &&
|
||||
(root.parent as BinaryExpression).left === root) {
|
||||
hasRest = true;
|
||||
break;
|
||||
}
|
||||
root = root.parent;
|
||||
}
|
||||
return;
|
||||
|
||||
case SyntaxKind.CallSignature:
|
||||
@@ -1961,9 +2007,10 @@ namespace ts {
|
||||
case SyntaxKind.JSDocFunctionType:
|
||||
return bindFunctionOrConstructorType(<SignatureDeclaration>node);
|
||||
case SyntaxKind.TypeLiteral:
|
||||
case SyntaxKind.MappedType:
|
||||
case SyntaxKind.JSDocTypeLiteral:
|
||||
case SyntaxKind.JSDocRecordType:
|
||||
return bindAnonymousDeclaration(<TypeLiteralNode>node, SymbolFlags.TypeLiteral, "__type");
|
||||
return bindAnonymousDeclaration(<Declaration>node, SymbolFlags.TypeLiteral, "__type");
|
||||
case SyntaxKind.ObjectLiteralExpression:
|
||||
return bindObjectLiteralExpression(<ObjectLiteralExpression>node);
|
||||
case SyntaxKind.FunctionExpression:
|
||||
@@ -2188,15 +2235,6 @@ namespace ts {
|
||||
}
|
||||
|
||||
function bindClassLikeDeclaration(node: ClassLikeDeclaration) {
|
||||
if (!isDeclarationFile(file) && !isInAmbientContext(node)) {
|
||||
if (getClassExtendsHeritageClauseElement(node) !== undefined) {
|
||||
emitFlags |= NodeFlags.HasClassExtends;
|
||||
}
|
||||
if (nodeIsDecorated(node)) {
|
||||
emitFlags |= NodeFlags.HasDecorators;
|
||||
}
|
||||
}
|
||||
|
||||
if (node.kind === SyntaxKind.ClassDeclaration) {
|
||||
bindBlockScopedDeclaration(node, SymbolFlags.Class, SymbolFlags.ClassExcludes);
|
||||
}
|
||||
@@ -2266,12 +2304,6 @@ namespace ts {
|
||||
}
|
||||
|
||||
function bindParameter(node: ParameterDeclaration) {
|
||||
if (!isDeclarationFile(file) &&
|
||||
!isInAmbientContext(node) &&
|
||||
nodeIsDecorated(node)) {
|
||||
emitFlags |= (NodeFlags.HasDecorators | NodeFlags.HasParamDecorators);
|
||||
}
|
||||
|
||||
if (inStrictMode) {
|
||||
// It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a
|
||||
// strict mode FunctionLikeDeclaration or FunctionExpression(13.1)
|
||||
@@ -2329,9 +2361,6 @@ namespace ts {
|
||||
if (isAsyncFunction(node)) {
|
||||
emitFlags |= NodeFlags.HasAsyncFunctions;
|
||||
}
|
||||
if (nodeIsDecorated(node)) {
|
||||
emitFlags |= NodeFlags.HasDecorators;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentFlow && isObjectLiteralOrClassExpressionMethod(node)) {
|
||||
@@ -2498,9 +2527,9 @@ namespace ts {
|
||||
transformFlags |= TransformFlags.AssertTypeScript;
|
||||
}
|
||||
|
||||
if (subtreeFlags & TransformFlags.ContainsSpreadElementExpression
|
||||
if (subtreeFlags & TransformFlags.ContainsSpread
|
||||
|| isSuperOrSuperProperty(expression, expressionKind)) {
|
||||
// If the this node contains a SpreadElementExpression, or is a super call, then it is an ES6
|
||||
// If the this node contains a SpreadExpression, or is a super call, then it is an ES6
|
||||
// node.
|
||||
transformFlags |= TransformFlags.AssertES2015;
|
||||
}
|
||||
@@ -2529,7 +2558,7 @@ namespace ts {
|
||||
if (node.typeArguments) {
|
||||
transformFlags |= TransformFlags.AssertTypeScript;
|
||||
}
|
||||
if (subtreeFlags & TransformFlags.ContainsSpreadElementExpression) {
|
||||
if (subtreeFlags & TransformFlags.ContainsSpread) {
|
||||
// If the this node contains a SpreadElementExpression then it is an ES6
|
||||
// node.
|
||||
transformFlags |= TransformFlags.AssertES2015;
|
||||
@@ -2538,16 +2567,18 @@ namespace ts {
|
||||
return transformFlags & ~TransformFlags.ArrayLiteralOrCallOrNewExcludes;
|
||||
}
|
||||
|
||||
|
||||
function computeBinaryExpression(node: BinaryExpression, subtreeFlags: TransformFlags) {
|
||||
let transformFlags = subtreeFlags;
|
||||
const operatorTokenKind = node.operatorToken.kind;
|
||||
const leftKind = node.left.kind;
|
||||
|
||||
if (operatorTokenKind === SyntaxKind.EqualsToken
|
||||
&& (leftKind === SyntaxKind.ObjectLiteralExpression
|
||||
|| leftKind === SyntaxKind.ArrayLiteralExpression)) {
|
||||
// Destructuring assignments are ES6 syntax.
|
||||
if (operatorTokenKind === SyntaxKind.EqualsToken && leftKind === SyntaxKind.ObjectLiteralExpression) {
|
||||
// Destructuring object assignments with are ES2015 syntax
|
||||
// and possibly ESNext if they contain rest
|
||||
transformFlags |= TransformFlags.AssertESNext | TransformFlags.AssertES2015 | TransformFlags.AssertDestructuringAssignment;
|
||||
}
|
||||
else if (operatorTokenKind === SyntaxKind.EqualsToken && leftKind === SyntaxKind.ArrayLiteralExpression) {
|
||||
// Destructuring assignments are ES2015 syntax.
|
||||
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.AssertDestructuringAssignment;
|
||||
}
|
||||
else if (operatorTokenKind === SyntaxKind.AsteriskAsteriskToken
|
||||
@@ -2581,6 +2612,11 @@ namespace ts {
|
||||
transformFlags |= TransformFlags.AssertTypeScript | TransformFlags.ContainsParameterPropertyAssignments;
|
||||
}
|
||||
|
||||
// parameters with object rest destructuring are ES Next syntax
|
||||
if (subtreeFlags & TransformFlags.ContainsObjectRest) {
|
||||
transformFlags |= TransformFlags.AssertESNext;
|
||||
}
|
||||
|
||||
// If a parameter has an initializer, a binding pattern or a dotDotDot token, then
|
||||
// it is ES6 syntax and its container must emit default value assignments or parameter destructuring downlevel.
|
||||
if (subtreeFlags & TransformFlags.ContainsBindingPattern || initializer || dotDotDotToken) {
|
||||
@@ -2699,7 +2735,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
node.transformFlags = transformFlags | TransformFlags.HasComputedFlags;
|
||||
return transformFlags & ~TransformFlags.NodeExcludes;
|
||||
return transformFlags & ~TransformFlags.CatchClauseExcludes;
|
||||
}
|
||||
|
||||
function computeExpressionWithTypeArguments(node: ExpressionWithTypeArguments, subtreeFlags: TransformFlags) {
|
||||
@@ -2726,6 +2762,11 @@ namespace ts {
|
||||
transformFlags |= TransformFlags.AssertTypeScript;
|
||||
}
|
||||
|
||||
// function declarations with object rest destructuring are ES Next syntax
|
||||
if (subtreeFlags & TransformFlags.ContainsObjectRest) {
|
||||
transformFlags |= TransformFlags.AssertESNext;
|
||||
}
|
||||
|
||||
node.transformFlags = transformFlags | TransformFlags.HasComputedFlags;
|
||||
return transformFlags & ~TransformFlags.ConstructorExcludes;
|
||||
}
|
||||
@@ -2744,6 +2785,11 @@ namespace ts {
|
||||
transformFlags |= TransformFlags.AssertTypeScript;
|
||||
}
|
||||
|
||||
// function declarations with object rest destructuring are ES Next syntax
|
||||
if (subtreeFlags & TransformFlags.ContainsObjectRest) {
|
||||
transformFlags |= TransformFlags.AssertESNext;
|
||||
}
|
||||
|
||||
// An async method declaration is ES2017 syntax.
|
||||
if (hasModifier(node, ModifierFlags.Async)) {
|
||||
transformFlags |= TransformFlags.AssertES2017;
|
||||
@@ -2770,6 +2816,11 @@ namespace ts {
|
||||
transformFlags |= TransformFlags.AssertTypeScript;
|
||||
}
|
||||
|
||||
// function declarations with object rest destructuring are ES Next syntax
|
||||
if (subtreeFlags & TransformFlags.ContainsObjectRest) {
|
||||
transformFlags |= TransformFlags.AssertESNext;
|
||||
}
|
||||
|
||||
node.transformFlags = transformFlags | TransformFlags.HasComputedFlags;
|
||||
return transformFlags & ~TransformFlags.MethodOrAccessorExcludes;
|
||||
}
|
||||
@@ -2814,6 +2865,11 @@ namespace ts {
|
||||
transformFlags |= TransformFlags.AssertES2017;
|
||||
}
|
||||
|
||||
// function declarations with object rest destructuring are ES Next syntax
|
||||
if (subtreeFlags & TransformFlags.ContainsObjectRest) {
|
||||
transformFlags |= TransformFlags.AssertESNext;
|
||||
}
|
||||
|
||||
// If a FunctionDeclaration's subtree has marked the container as needing to capture the
|
||||
// lexical this, or the function contains parameters with initializers, then this node is
|
||||
// ES6 syntax.
|
||||
@@ -2851,6 +2907,12 @@ namespace ts {
|
||||
transformFlags |= TransformFlags.AssertES2017;
|
||||
}
|
||||
|
||||
// function expressions with object rest destructuring are ES Next syntax
|
||||
if (subtreeFlags & TransformFlags.ContainsObjectRest) {
|
||||
transformFlags |= TransformFlags.AssertESNext;
|
||||
}
|
||||
|
||||
|
||||
// If a FunctionExpression's subtree has marked the container as needing to capture the
|
||||
// lexical this, or the function contains parameters with initializers, then this node is
|
||||
// ES6 syntax.
|
||||
@@ -2888,6 +2950,11 @@ namespace ts {
|
||||
transformFlags |= TransformFlags.AssertES2017;
|
||||
}
|
||||
|
||||
// arrow functions with object rest destructuring are ES Next syntax
|
||||
if (subtreeFlags & TransformFlags.ContainsObjectRest) {
|
||||
transformFlags |= TransformFlags.AssertESNext;
|
||||
}
|
||||
|
||||
// If an ArrowFunction contains a lexical this, its container must capture the lexical this.
|
||||
if (subtreeFlags & TransformFlags.ContainsLexicalThis) {
|
||||
transformFlags |= TransformFlags.ContainsCapturedLexicalThis;
|
||||
@@ -2914,11 +2981,11 @@ namespace ts {
|
||||
|
||||
function computeVariableDeclaration(node: VariableDeclaration, subtreeFlags: TransformFlags) {
|
||||
let transformFlags = subtreeFlags;
|
||||
const nameKind = node.name.kind;
|
||||
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.ContainsBindingPattern;
|
||||
|
||||
// A VariableDeclaration with a binding pattern is ES6 syntax.
|
||||
if (nameKind === SyntaxKind.ObjectBindingPattern || nameKind === SyntaxKind.ArrayBindingPattern) {
|
||||
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.ContainsBindingPattern;
|
||||
// A VariableDeclaration containing ObjectRest is ESNext syntax
|
||||
if (subtreeFlags & TransformFlags.ContainsObjectRest) {
|
||||
transformFlags |= TransformFlags.AssertESNext;
|
||||
}
|
||||
|
||||
// Type annotations are TypeScript syntax.
|
||||
@@ -3058,6 +3125,10 @@ namespace ts {
|
||||
transformFlags |= TransformFlags.AssertJsx;
|
||||
break;
|
||||
|
||||
case SyntaxKind.ForOfStatement:
|
||||
// for-of might be ESNext if it has a rest destructuring
|
||||
transformFlags |= TransformFlags.AssertESNext;
|
||||
// FALLTHROUGH
|
||||
case SyntaxKind.NoSubstitutionTemplateLiteral:
|
||||
case SyntaxKind.TemplateHead:
|
||||
case SyntaxKind.TemplateMiddle:
|
||||
@@ -3110,6 +3181,7 @@ namespace ts {
|
||||
case SyntaxKind.ThisType:
|
||||
case SyntaxKind.TypeOperator:
|
||||
case SyntaxKind.IndexedAccessType:
|
||||
case SyntaxKind.MappedType:
|
||||
case SyntaxKind.LiteralType:
|
||||
// Types and signatures are TypeScript syntax, and exclude all other facts.
|
||||
transformFlags = TransformFlags.AssertTypeScript;
|
||||
@@ -3134,9 +3206,12 @@ namespace ts {
|
||||
}
|
||||
break;
|
||||
|
||||
case SyntaxKind.SpreadElementExpression:
|
||||
// This node is ES6 syntax, but is handled by a containing node.
|
||||
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.ContainsSpreadElementExpression;
|
||||
case SyntaxKind.SpreadElement:
|
||||
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.ContainsSpread;
|
||||
break;
|
||||
|
||||
case SyntaxKind.SpreadAssignment:
|
||||
transformFlags |= TransformFlags.AssertESNext | TransformFlags.ContainsObjectSpread;
|
||||
break;
|
||||
|
||||
case SyntaxKind.SuperKeyword:
|
||||
@@ -3150,9 +3225,23 @@ namespace ts {
|
||||
break;
|
||||
|
||||
case SyntaxKind.ObjectBindingPattern:
|
||||
case SyntaxKind.ArrayBindingPattern:
|
||||
// These nodes are ES6 syntax.
|
||||
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.ContainsBindingPattern;
|
||||
if (subtreeFlags & TransformFlags.ContainsRest) {
|
||||
transformFlags |= TransformFlags.AssertESNext | TransformFlags.ContainsObjectRest;
|
||||
}
|
||||
excludeFlags = TransformFlags.BindingPatternExcludes;
|
||||
break;
|
||||
|
||||
case SyntaxKind.ArrayBindingPattern:
|
||||
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.ContainsBindingPattern;
|
||||
excludeFlags = TransformFlags.BindingPatternExcludes;
|
||||
break;
|
||||
|
||||
case SyntaxKind.BindingElement:
|
||||
transformFlags |= TransformFlags.AssertES2015;
|
||||
if ((<BindingElement>node).dotDotDotToken) {
|
||||
transformFlags |= TransformFlags.ContainsRest;
|
||||
}
|
||||
break;
|
||||
|
||||
case SyntaxKind.Decorator:
|
||||
@@ -3174,13 +3263,19 @@ namespace ts {
|
||||
transformFlags |= TransformFlags.ContainsLexicalThis;
|
||||
}
|
||||
|
||||
if (subtreeFlags & TransformFlags.ContainsObjectSpread) {
|
||||
// If an ObjectLiteralExpression contains a spread element, then it
|
||||
// is an ES next node.
|
||||
transformFlags |= TransformFlags.AssertESNext;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SyntaxKind.ArrayLiteralExpression:
|
||||
case SyntaxKind.NewExpression:
|
||||
excludeFlags = TransformFlags.ArrayLiteralOrCallOrNewExcludes;
|
||||
if (subtreeFlags & TransformFlags.ContainsSpreadElementExpression) {
|
||||
// If the this node contains a SpreadElementExpression, then it is an ES6
|
||||
if (subtreeFlags & TransformFlags.ContainsSpread) {
|
||||
// If the this node contains a SpreadExpression, then it is an ES6
|
||||
// node.
|
||||
transformFlags |= TransformFlags.AssertES2015;
|
||||
}
|
||||
@@ -3272,6 +3367,11 @@ namespace ts {
|
||||
return TransformFlags.TypeExcludes;
|
||||
case SyntaxKind.ObjectLiteralExpression:
|
||||
return TransformFlags.ObjectLiteralExcludes;
|
||||
case SyntaxKind.CatchClause:
|
||||
return TransformFlags.CatchClauseExcludes;
|
||||
case SyntaxKind.ObjectBindingPattern:
|
||||
case SyntaxKind.ArrayBindingPattern:
|
||||
return TransformFlags.BindingPatternExcludes;
|
||||
default:
|
||||
return TransformFlags.NodeExcludes;
|
||||
}
|
||||
|
||||
+710
-257
File diff suppressed because it is too large
Load Diff
@@ -77,6 +77,11 @@ namespace ts {
|
||||
type: "string",
|
||||
description: Diagnostics.Specify_the_object_invoked_for_createElement_and_spread_when_targeting_react_JSX_emit
|
||||
},
|
||||
{
|
||||
name: "jsxFactory",
|
||||
type: "string",
|
||||
description: Diagnostics.Specify_the_JSX_factory_function_to_use_when_targeting_react_JSX_emit_e_g_React_createElement_or_h
|
||||
},
|
||||
{
|
||||
name: "listFiles",
|
||||
type: "boolean",
|
||||
@@ -264,7 +269,8 @@ namespace ts {
|
||||
"es6": ScriptTarget.ES2015,
|
||||
"es2015": ScriptTarget.ES2015,
|
||||
"es2016": ScriptTarget.ES2016,
|
||||
"es2017": ScriptTarget.ES2017
|
||||
"es2017": ScriptTarget.ES2017,
|
||||
"esnext": ScriptTarget.ESNext,
|
||||
}),
|
||||
description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015,
|
||||
paramType: Diagnostics.VERSION,
|
||||
@@ -429,6 +435,7 @@ namespace ts {
|
||||
"es2016.array.include": "lib.es2016.array.include.d.ts",
|
||||
"es2017.object": "lib.es2017.object.d.ts",
|
||||
"es2017.sharedmemory": "lib.es2017.sharedmemory.d.ts",
|
||||
"es2017.string": "lib.es2017.string.d.ts",
|
||||
}),
|
||||
},
|
||||
description: Diagnostics.Specify_library_files_to_be_included_in_the_compilation_Colon
|
||||
|
||||
+19
-2
@@ -1,6 +1,11 @@
|
||||
/// <reference path="types.ts"/>
|
||||
/// <reference path="performance.ts" />
|
||||
|
||||
namespace ts {
|
||||
/** The version of the TypeScript compiler release */
|
||||
export const version = "2.2.0";
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
namespace ts {
|
||||
/**
|
||||
@@ -821,6 +826,13 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
export function appendProperty<T>(map: Map<T>, key: string | number, value: T): Map<T> {
|
||||
if (key === undefined || value === undefined) return map;
|
||||
if (map === undefined) map = createMap<T>();
|
||||
map[key] = value;
|
||||
return map;
|
||||
}
|
||||
|
||||
export function assign<T1 extends MapLike<{}>, T2, T3>(t: T1, arg1: T2, arg2: T3): T1 & T2 & T3;
|
||||
export function assign<T1 extends MapLike<{}>, T2>(t: T1, arg1: T2): T1 & T2;
|
||||
export function assign<T1 extends MapLike<{}>>(t: T1, ...args: any[]): any;
|
||||
@@ -2231,6 +2243,13 @@ namespace ts {
|
||||
* Path must have a valid extension.
|
||||
*/
|
||||
export function extensionFromPath(path: string): Extension {
|
||||
const ext = tryGetExtensionFromPath(path);
|
||||
if (ext !== undefined) {
|
||||
return ext;
|
||||
}
|
||||
Debug.fail(`File ${path} has unknown extension.`);
|
||||
}
|
||||
export function tryGetExtensionFromPath(path: string): Extension | undefined {
|
||||
if (fileExtensionIs(path, ".d.ts")) {
|
||||
return Extension.Dts;
|
||||
}
|
||||
@@ -2246,7 +2265,5 @@ namespace ts {
|
||||
if (fileExtensionIs(path, ".jsx")) {
|
||||
return Extension.Jsx;
|
||||
}
|
||||
Debug.fail(`File ${path} has unknown extension.`);
|
||||
return Extension.Js;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -416,7 +416,9 @@ namespace ts {
|
||||
case SyntaxKind.TypeOperator:
|
||||
return emitTypeOperator(<TypeOperatorNode>type);
|
||||
case SyntaxKind.IndexedAccessType:
|
||||
return emitPropertyAccessType(<IndexedAccessTypeNode>type);
|
||||
return emitIndexedAccessType(<IndexedAccessTypeNode>type);
|
||||
case SyntaxKind.MappedType:
|
||||
return emitMappedType(<MappedTypeNode>type);
|
||||
case SyntaxKind.FunctionType:
|
||||
case SyntaxKind.ConstructorType:
|
||||
return emitSignatureDeclarationWithJsDocComments(<FunctionOrConstructorTypeNode>type);
|
||||
@@ -516,13 +518,39 @@ namespace ts {
|
||||
emitType(type.type);
|
||||
}
|
||||
|
||||
function emitPropertyAccessType(node: IndexedAccessTypeNode) {
|
||||
function emitIndexedAccessType(node: IndexedAccessTypeNode) {
|
||||
emitType(node.objectType);
|
||||
write("[");
|
||||
emitType(node.indexType);
|
||||
write("]");
|
||||
}
|
||||
|
||||
function emitMappedType(node: MappedTypeNode) {
|
||||
const prevEnclosingDeclaration = enclosingDeclaration;
|
||||
enclosingDeclaration = node;
|
||||
write("{");
|
||||
writeLine();
|
||||
increaseIndent();
|
||||
if (node.readonlyToken) {
|
||||
write("readonly ");
|
||||
}
|
||||
write("[");
|
||||
writeEntityName(node.typeParameter.name);
|
||||
write(" in ");
|
||||
emitType(node.typeParameter.constraint);
|
||||
write("]");
|
||||
if (node.questionToken) {
|
||||
write("?");
|
||||
}
|
||||
write(": ");
|
||||
emitType(node.type);
|
||||
write(";");
|
||||
writeLine();
|
||||
decreaseIndent();
|
||||
write("}");
|
||||
enclosingDeclaration = prevEnclosingDeclaration;
|
||||
}
|
||||
|
||||
function emitTypeLiteral(type: TypeLiteralNode) {
|
||||
write("{");
|
||||
if (type.members.length) {
|
||||
|
||||
@@ -1027,6 +1027,10 @@
|
||||
"category": "Error",
|
||||
"code": 2342
|
||||
},
|
||||
"This syntax requires an imported helper named '{1}', but module '{0}' has no exported member '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 2343
|
||||
},
|
||||
"Type '{0}' does not satisfy the constraint '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 2344
|
||||
@@ -1067,6 +1071,10 @@
|
||||
"category": "Error",
|
||||
"code": 2353
|
||||
},
|
||||
"This syntax requires an imported helper but module '{0}' cannot be found.": {
|
||||
"category": "Error",
|
||||
"code": 2354
|
||||
},
|
||||
"A function whose declared type is neither 'void' nor 'any' must return a value.": {
|
||||
"category": "Error",
|
||||
"code": 2355
|
||||
@@ -1459,7 +1467,7 @@
|
||||
"category": "Error",
|
||||
"code": 2461
|
||||
},
|
||||
"A rest element must be last in an array destructuring pattern": {
|
||||
"A rest element must be last in a destructuring pattern": {
|
||||
"category": "Error",
|
||||
"code": 2462
|
||||
},
|
||||
@@ -1999,6 +2007,18 @@
|
||||
"category": "Error",
|
||||
"code": 2697
|
||||
},
|
||||
"Spread types may only be created from object types.": {
|
||||
"category": "Error",
|
||||
"code": 2698
|
||||
},
|
||||
"Rest types may only be created from object types.": {
|
||||
"category": "Error",
|
||||
"code": 2700
|
||||
},
|
||||
"The target of an object rest assignment must be a variable or a property access.": {
|
||||
"category": "Error",
|
||||
"code": 2701
|
||||
},
|
||||
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
@@ -2397,6 +2417,10 @@
|
||||
"category": "Error",
|
||||
"code": 5066
|
||||
},
|
||||
"Invalid value for 'jsxFactory'. '{0}' is not a valid identifier or qualified-name.": {
|
||||
"category": "Error",
|
||||
"code": 5067
|
||||
},
|
||||
"Concatenate and emit output to single file.": {
|
||||
"category": "Message",
|
||||
"code": 6001
|
||||
@@ -2913,6 +2937,10 @@
|
||||
"category": "Message",
|
||||
"code": 6145
|
||||
},
|
||||
"Specify the JSX factory function to use when targeting 'react' JSX emit, e.g. 'React.createElement' or 'h'.": {
|
||||
"category": "Message",
|
||||
"code": 6146
|
||||
},
|
||||
"Variable '{0}' implicitly has an '{1}' type.": {
|
||||
"category": "Error",
|
||||
"code": 7005
|
||||
@@ -3085,6 +3113,10 @@
|
||||
"category": "Error",
|
||||
"code": 9003
|
||||
},
|
||||
"Language service is disabled.": {
|
||||
"category": "Error",
|
||||
"code": 9004
|
||||
},
|
||||
"JSX attributes must only be assigned a non-empty 'expression'.": {
|
||||
"category": "Error",
|
||||
"code": 17000
|
||||
@@ -3178,5 +3210,9 @@
|
||||
"Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig": {
|
||||
"category": "Error",
|
||||
"code": 90009
|
||||
},
|
||||
"Type '{0}' is not assignable to type '{1}'. Two different types with this name exist, but they are unrelated.": {
|
||||
"category": "Error",
|
||||
"code": 90010
|
||||
}
|
||||
}
|
||||
|
||||
+39
-5
@@ -421,7 +421,9 @@ namespace ts {
|
||||
case SyntaxKind.TypeOperator:
|
||||
return emitTypeOperator(<TypeOperatorNode>node);
|
||||
case SyntaxKind.IndexedAccessType:
|
||||
return emitPropertyAccessType(<IndexedAccessTypeNode>node);
|
||||
return emitIndexedAccessType(<IndexedAccessTypeNode>node);
|
||||
case SyntaxKind.MappedType:
|
||||
return emitMappedType(<MappedTypeNode>node);
|
||||
case SyntaxKind.LiteralType:
|
||||
return emitLiteralType(<LiteralTypeNode>node);
|
||||
|
||||
@@ -556,6 +558,8 @@ namespace ts {
|
||||
return emitPropertyAssignment(<PropertyAssignment>node);
|
||||
case SyntaxKind.ShorthandPropertyAssignment:
|
||||
return emitShorthandPropertyAssignment(<ShorthandPropertyAssignment>node);
|
||||
case SyntaxKind.SpreadAssignment:
|
||||
return emitSpreadAssignment(node as SpreadAssignment);
|
||||
|
||||
// Enum
|
||||
case SyntaxKind.EnumMember:
|
||||
@@ -646,8 +650,8 @@ namespace ts {
|
||||
return emitTemplateExpression(<TemplateExpression>node);
|
||||
case SyntaxKind.YieldExpression:
|
||||
return emitYieldExpression(<YieldExpression>node);
|
||||
case SyntaxKind.SpreadElementExpression:
|
||||
return emitSpreadElementExpression(<SpreadElementExpression>node);
|
||||
case SyntaxKind.SpreadElement:
|
||||
return emitSpreadExpression(<SpreadElement>node);
|
||||
case SyntaxKind.ClassExpression:
|
||||
return emitClassExpression(<ClassExpression>node);
|
||||
case SyntaxKind.OmittedExpression:
|
||||
@@ -919,13 +923,36 @@ namespace ts {
|
||||
emit(node.type);
|
||||
}
|
||||
|
||||
function emitPropertyAccessType(node: IndexedAccessTypeNode) {
|
||||
function emitIndexedAccessType(node: IndexedAccessTypeNode) {
|
||||
emit(node.objectType);
|
||||
write("[");
|
||||
emit(node.indexType);
|
||||
write("]");
|
||||
}
|
||||
|
||||
function emitMappedType(node: MappedTypeNode) {
|
||||
write("{");
|
||||
writeLine();
|
||||
increaseIndent();
|
||||
if (node.readonlyToken) {
|
||||
write("readonly ");
|
||||
}
|
||||
write("[");
|
||||
emit(node.typeParameter.name);
|
||||
write(" in ");
|
||||
emit(node.typeParameter.constraint);
|
||||
write("]");
|
||||
if (node.questionToken) {
|
||||
write("?");
|
||||
}
|
||||
write(": ");
|
||||
emit(node.type);
|
||||
write(";");
|
||||
writeLine();
|
||||
decreaseIndent();
|
||||
write("}");
|
||||
}
|
||||
|
||||
function emitLiteralType(node: LiteralTypeNode) {
|
||||
emitExpression(node.literal);
|
||||
}
|
||||
@@ -1195,7 +1222,7 @@ namespace ts {
|
||||
emitExpressionWithPrefix(" ", node.expression);
|
||||
}
|
||||
|
||||
function emitSpreadElementExpression(node: SpreadElementExpression) {
|
||||
function emitSpreadExpression(node: SpreadElement) {
|
||||
write("...");
|
||||
emitExpression(node.expression);
|
||||
}
|
||||
@@ -1927,6 +1954,13 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function emitSpreadAssignment(node: SpreadAssignment) {
|
||||
if (node.expression) {
|
||||
write("...");
|
||||
emitExpression(node.expression);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Enum
|
||||
//
|
||||
|
||||
+365
-24
@@ -103,12 +103,12 @@ namespace ts {
|
||||
|
||||
// Literals
|
||||
|
||||
export function createLiteral(textSource: StringLiteral | Identifier, location?: TextRange): StringLiteral;
|
||||
export function createLiteral(textSource: StringLiteral | NumericLiteral | Identifier, location?: TextRange): StringLiteral;
|
||||
export function createLiteral(value: string, location?: TextRange): StringLiteral;
|
||||
export function createLiteral(value: number, location?: TextRange): NumericLiteral;
|
||||
export function createLiteral(value: boolean, location?: TextRange): BooleanLiteral;
|
||||
export function createLiteral(value: string | number | boolean, location?: TextRange): PrimaryExpression;
|
||||
export function createLiteral(value: string | number | boolean | StringLiteral | Identifier, location?: TextRange): PrimaryExpression {
|
||||
export function createLiteral(value: string | number | boolean | StringLiteral | NumericLiteral | Identifier, location?: TextRange): PrimaryExpression {
|
||||
if (typeof value === "number") {
|
||||
const node = <NumericLiteral>createNode(SyntaxKind.NumericLiteral, location);
|
||||
node.text = value.toString();
|
||||
@@ -239,9 +239,9 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
export function updateParameter(node: ParameterDeclaration, decorators: Decorator[], modifiers: Modifier[], name: BindingName, type: TypeNode, initializer: Expression) {
|
||||
if (node.decorators !== decorators || node.modifiers !== modifiers || node.name !== name || node.type !== type || node.initializer !== initializer) {
|
||||
return updateNode(createParameter(decorators, modifiers, node.dotDotDotToken, name, node.questionToken, type, initializer, /*location*/ node), node);
|
||||
export function updateParameter(node: ParameterDeclaration, decorators: Decorator[], modifiers: Modifier[], dotDotDotToken: DotDotDotToken, name: BindingName, type: TypeNode, initializer: Expression) {
|
||||
if (node.decorators !== decorators || node.modifiers !== modifiers || node.dotDotDotToken !== dotDotDotToken || node.name !== name || node.type !== type || node.initializer !== initializer) {
|
||||
return updateNode(createParameter(decorators, modifiers, dotDotDotToken, name, node.questionToken, type, initializer, /*location*/ node), node);
|
||||
}
|
||||
|
||||
return node;
|
||||
@@ -379,9 +379,9 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
export function updateBindingElement(node: BindingElement, propertyName: PropertyName, name: BindingName, initializer: Expression) {
|
||||
if (node.propertyName !== propertyName || node.name !== name || node.initializer !== initializer) {
|
||||
return updateNode(createBindingElement(propertyName, node.dotDotDotToken, name, initializer, node), node);
|
||||
export function updateBindingElement(node: BindingElement, dotDotDotToken: DotDotDotToken, propertyName: PropertyName, name: BindingName, initializer: Expression) {
|
||||
if (node.propertyName !== propertyName || node.dotDotDotToken !== dotDotDotToken || node.name !== name || node.initializer !== initializer) {
|
||||
return updateNode(createBindingElement(propertyName, dotDotDotToken, name, initializer, node), node);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
@@ -647,13 +647,25 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
export function createConditional(condition: Expression, questionToken: QuestionToken, whenTrue: Expression, colonToken: ColonToken, whenFalse: Expression, location?: TextRange) {
|
||||
const node = <ConditionalExpression>createNode(SyntaxKind.ConditionalExpression, location);
|
||||
node.condition = parenthesizeConditionalHead(condition);
|
||||
node.questionToken = questionToken;
|
||||
node.whenTrue = whenTrue;
|
||||
node.colonToken = colonToken;
|
||||
node.whenFalse = whenFalse;
|
||||
export function createConditional(condition: Expression, whenTrue: Expression, whenFalse: Expression, location?: TextRange): ConditionalExpression;
|
||||
export function createConditional(condition: Expression, questionToken: QuestionToken, whenTrue: Expression, colonToken: ColonToken, whenFalse: Expression, location?: TextRange): ConditionalExpression;
|
||||
export function createConditional(condition: Expression, questionTokenOrWhenTrue: QuestionToken | Expression, whenTrueOrWhenFalse: Expression, colonTokenOrLocation?: ColonToken | TextRange, whenFalse?: Expression, location?: TextRange) {
|
||||
const node = <ConditionalExpression>createNode(SyntaxKind.ConditionalExpression, whenFalse ? location : colonTokenOrLocation);
|
||||
node.condition = parenthesizeForConditionalHead(condition);
|
||||
if (whenFalse) {
|
||||
// second overload
|
||||
node.questionToken = <QuestionToken>questionTokenOrWhenTrue;
|
||||
node.whenTrue = whenTrueOrWhenFalse;
|
||||
node.colonToken = <ColonToken>colonTokenOrLocation;
|
||||
node.whenFalse = whenFalse;
|
||||
}
|
||||
else {
|
||||
// first overload
|
||||
node.questionToken = createToken(SyntaxKind.QuestionToken);
|
||||
node.whenTrue = <Expression>questionTokenOrWhenTrue;
|
||||
node.colonToken = createToken(SyntaxKind.ColonToken);
|
||||
node.whenFalse = whenTrueOrWhenFalse;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -693,12 +705,12 @@ namespace ts {
|
||||
}
|
||||
|
||||
export function createSpread(expression: Expression, location?: TextRange) {
|
||||
const node = <SpreadElementExpression>createNode(SyntaxKind.SpreadElementExpression, location);
|
||||
const node = <SpreadElement>createNode(SyntaxKind.SpreadElement, location);
|
||||
node.expression = parenthesizeExpressionForList(expression);
|
||||
return node;
|
||||
}
|
||||
|
||||
export function updateSpread(node: SpreadElementExpression, expression: Expression) {
|
||||
export function updateSpread(node: SpreadElement, expression: Expression) {
|
||||
if (node.expression !== expression) {
|
||||
return updateNode(createSpread(expression, node), node);
|
||||
}
|
||||
@@ -1403,6 +1415,12 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
export function createSpreadAssignment(expression: Expression, location?: TextRange) {
|
||||
const node = <SpreadAssignment>createNode(SyntaxKind.SpreadAssignment, location);
|
||||
node.expression = expression !== undefined ? parenthesizeExpressionForList(expression) : undefined;
|
||||
return node;
|
||||
}
|
||||
|
||||
export function updateShorthandPropertyAssignment(node: ShorthandPropertyAssignment, name: Identifier, objectAssignmentInitializer: Expression) {
|
||||
if (node.name !== name || node.objectAssignmentInitializer !== objectAssignmentInitializer) {
|
||||
return updateNode(createShorthandPropertyAssignment(name, objectAssignmentInitializer, node), node);
|
||||
@@ -1410,6 +1428,13 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
export function updateSpreadAssignment(node: SpreadAssignment, expression: Expression) {
|
||||
if (node.expression !== expression) {
|
||||
return updateNode(createSpreadAssignment(expression, node), node);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
// Top-level nodes
|
||||
|
||||
export function updateSourceFileNode(node: SourceFile, statements: Statement[]) {
|
||||
@@ -1532,6 +1557,8 @@ namespace ts {
|
||||
return <Expression>createBinary(left, SyntaxKind.LessThanToken, right, location);
|
||||
}
|
||||
|
||||
export function createAssignment(left: ObjectLiteralExpression | ArrayLiteralExpression, right: Expression, location?: TextRange): DestructuringAssignment;
|
||||
export function createAssignment(left: Expression, right: Expression, location?: TextRange): BinaryExpression;
|
||||
export function createAssignment(left: Expression, right: Expression, location?: TextRange) {
|
||||
return createBinary(left, SyntaxKind.EqualsToken, right, location);
|
||||
}
|
||||
@@ -1572,6 +1599,14 @@ namespace ts {
|
||||
return createVoid(createLiteral(0));
|
||||
}
|
||||
|
||||
export type TypeOfTag = "undefined" | "number" | "boolean" | "string" | "symbol" | "object" | "function";
|
||||
|
||||
export function createTypeCheck(value: Expression, tag: TypeOfTag) {
|
||||
return tag === "undefined"
|
||||
? createStrictEquality(value, createVoidZero())
|
||||
: createStrictEquality(createTypeOf(value), createLiteral(tag));
|
||||
}
|
||||
|
||||
export function createMemberAccessForPropertyName(target: Expression, memberName: PropertyName, location?: TextRange): MemberExpression {
|
||||
if (isComputedPropertyName(memberName)) {
|
||||
return createElementAccess(target, memberName.expression, location);
|
||||
@@ -1645,7 +1680,34 @@ namespace ts {
|
||||
return react;
|
||||
}
|
||||
|
||||
export function createReactCreateElement(reactNamespace: string, tagName: Expression, props: Expression, children: Expression[], parentElement: JsxOpeningLikeElement, location: TextRange): LeftHandSideExpression {
|
||||
function createJsxFactoryExpressionFromEntityName(jsxFactory: EntityName, parent: JsxOpeningLikeElement): Expression {
|
||||
if (isQualifiedName(jsxFactory)) {
|
||||
return createPropertyAccess(
|
||||
createJsxFactoryExpressionFromEntityName(
|
||||
jsxFactory.left,
|
||||
parent
|
||||
),
|
||||
setEmitFlags(
|
||||
getMutableClone(jsxFactory.right),
|
||||
EmitFlags.NoSourceMap
|
||||
)
|
||||
);
|
||||
}
|
||||
else {
|
||||
return createReactNamespace(jsxFactory.text, parent);
|
||||
}
|
||||
}
|
||||
|
||||
function createJsxFactoryExpression(jsxFactoryEntity: EntityName, reactNamespace: string, parent: JsxOpeningLikeElement): Expression {
|
||||
return jsxFactoryEntity ?
|
||||
createJsxFactoryExpressionFromEntityName(jsxFactoryEntity, parent) :
|
||||
createPropertyAccess(
|
||||
createReactNamespace(reactNamespace, parent),
|
||||
"createElement"
|
||||
);
|
||||
}
|
||||
|
||||
export function createExpressionForJsxElement(jsxFactoryEntity: EntityName, reactNamespace: string, tagName: Expression, props: Expression, children: Expression[], parentElement: JsxOpeningLikeElement, location: TextRange): LeftHandSideExpression {
|
||||
const argumentsList = [tagName];
|
||||
if (props) {
|
||||
argumentsList.push(props);
|
||||
@@ -1668,10 +1730,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
return createCall(
|
||||
createPropertyAccess(
|
||||
createReactNamespace(reactNamespace, parentElement),
|
||||
"createElement"
|
||||
),
|
||||
createJsxFactoryExpression(jsxFactoryEntity, reactNamespace, parentElement),
|
||||
/*typeArguments*/ undefined,
|
||||
argumentsList,
|
||||
location
|
||||
@@ -1847,6 +1906,9 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Utilities
|
||||
|
||||
export interface CallBinding {
|
||||
target: LeftHandSideExpression;
|
||||
thisArg: Expression;
|
||||
@@ -2196,8 +2258,8 @@ namespace ts {
|
||||
return qualifiedName;
|
||||
}
|
||||
|
||||
export function convertToFunctionBody(node: ConciseBody) {
|
||||
return isBlock(node) ? node : createBlock([createReturn(node, /*location*/ node)], /*location*/ node);
|
||||
export function convertToFunctionBody(node: ConciseBody, multiLine?: boolean) {
|
||||
return isBlock(node) ? node : createBlock([createReturn(node, /*location*/ node)], /*location*/ node, multiLine);
|
||||
}
|
||||
|
||||
function isUseStrictPrologue(node: ExpressionStatement): boolean {
|
||||
@@ -2472,6 +2534,16 @@ namespace ts {
|
||||
return SyntaxKind.Unknown;
|
||||
}
|
||||
|
||||
export function parenthesizeForConditionalHead(condition: Expression) {
|
||||
const conditionalPrecedence = getOperatorPrecedence(SyntaxKind.ConditionalExpression, SyntaxKind.QuestionToken);
|
||||
const emittedCondition = skipPartiallyEmittedExpressions(condition);
|
||||
const conditionPrecedence = getExpressionPrecedence(emittedCondition);
|
||||
if (compareValues(conditionPrecedence, conditionalPrecedence) === Comparison.LessThan) {
|
||||
return createParen(condition);
|
||||
}
|
||||
return condition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps an expression in parentheses if it is needed in order to use the expression
|
||||
* as the expression of a NewExpression node.
|
||||
@@ -3090,6 +3162,275 @@ namespace ts {
|
||||
return tryGetModuleNameFromFile(resolver.getExternalModuleFileFromDeclaration(declaration), host, compilerOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the initializer of an BindingOrAssignmentElement.
|
||||
*/
|
||||
export function getInitializerOfBindingOrAssignmentElement(bindingElement: BindingOrAssignmentElement): Expression | undefined {
|
||||
if (isDeclarationBindingElement(bindingElement)) {
|
||||
// `1` in `let { a = 1 } = ...`
|
||||
// `1` in `let { a: b = 1 } = ...`
|
||||
// `1` in `let { a: {b} = 1 } = ...`
|
||||
// `1` in `let { a: [b] = 1 } = ...`
|
||||
// `1` in `let [a = 1] = ...`
|
||||
// `1` in `let [{a} = 1] = ...`
|
||||
// `1` in `let [[a] = 1] = ...`
|
||||
return bindingElement.initializer;
|
||||
}
|
||||
|
||||
if (isPropertyAssignment(bindingElement)) {
|
||||
// `1` in `({ a: b = 1 } = ...)`
|
||||
// `1` in `({ a: {b} = 1 } = ...)`
|
||||
// `1` in `({ a: [b] = 1 } = ...)`
|
||||
return isAssignmentExpression(bindingElement.initializer, /*excludeCompoundAssignment*/ true)
|
||||
? bindingElement.initializer.right
|
||||
: undefined;
|
||||
}
|
||||
|
||||
if (isShorthandPropertyAssignment(bindingElement)) {
|
||||
// `1` in `({ a = 1 } = ...)`
|
||||
return bindingElement.objectAssignmentInitializer;
|
||||
}
|
||||
|
||||
if (isAssignmentExpression(bindingElement, /*excludeCompoundAssignment*/ true)) {
|
||||
// `1` in `[a = 1] = ...`
|
||||
// `1` in `[{a} = 1] = ...`
|
||||
// `1` in `[[a] = 1] = ...`
|
||||
return bindingElement.right;
|
||||
}
|
||||
|
||||
if (isSpreadExpression(bindingElement)) {
|
||||
// Recovery consistent with existing emit.
|
||||
return getInitializerOfBindingOrAssignmentElement(<BindingOrAssignmentElement>bindingElement.expression);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of an BindingOrAssignmentElement.
|
||||
*/
|
||||
export function getTargetOfBindingOrAssignmentElement(bindingElement: BindingOrAssignmentElement): BindingOrAssignmentElementTarget {
|
||||
if (isDeclarationBindingElement(bindingElement)) {
|
||||
// `a` in `let { a } = ...`
|
||||
// `a` in `let { a = 1 } = ...`
|
||||
// `b` in `let { a: b } = ...`
|
||||
// `b` in `let { a: b = 1 } = ...`
|
||||
// `a` in `let { ...a } = ...`
|
||||
// `{b}` in `let { a: {b} } = ...`
|
||||
// `{b}` in `let { a: {b} = 1 } = ...`
|
||||
// `[b]` in `let { a: [b] } = ...`
|
||||
// `[b]` in `let { a: [b] = 1 } = ...`
|
||||
// `a` in `let [a] = ...`
|
||||
// `a` in `let [a = 1] = ...`
|
||||
// `a` in `let [...a] = ...`
|
||||
// `{a}` in `let [{a}] = ...`
|
||||
// `{a}` in `let [{a} = 1] = ...`
|
||||
// `[a]` in `let [[a]] = ...`
|
||||
// `[a]` in `let [[a] = 1] = ...`
|
||||
return <ObjectBindingPattern | ArrayBindingPattern | Identifier>bindingElement.name;
|
||||
}
|
||||
|
||||
if (isObjectLiteralElementLike(bindingElement)) {
|
||||
switch (bindingElement.kind) {
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
// `b` in `({ a: b } = ...)`
|
||||
// `b` in `({ a: b = 1 } = ...)`
|
||||
// `{b}` in `({ a: {b} } = ...)`
|
||||
// `{b}` in `({ a: {b} = 1 } = ...)`
|
||||
// `[b]` in `({ a: [b] } = ...)`
|
||||
// `[b]` in `({ a: [b] = 1 } = ...)`
|
||||
// `b.c` in `({ a: b.c } = ...)`
|
||||
// `b.c` in `({ a: b.c = 1 } = ...)`
|
||||
// `b[0]` in `({ a: b[0] } = ...)`
|
||||
// `b[0]` in `({ a: b[0] = 1 } = ...)`
|
||||
return getTargetOfBindingOrAssignmentElement(<BindingOrAssignmentElement>bindingElement.initializer);
|
||||
|
||||
case SyntaxKind.ShorthandPropertyAssignment:
|
||||
// `a` in `({ a } = ...)`
|
||||
// `a` in `({ a = 1 } = ...)`
|
||||
return bindingElement.name;
|
||||
|
||||
case SyntaxKind.SpreadAssignment:
|
||||
// `a` in `({ ...a } = ...)`
|
||||
return getTargetOfBindingOrAssignmentElement(<BindingOrAssignmentElement>bindingElement.expression);
|
||||
}
|
||||
|
||||
// no target
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (isAssignmentExpression(bindingElement, /*excludeCompoundAssignment*/ true)) {
|
||||
// `a` in `[a = 1] = ...`
|
||||
// `{a}` in `[{a} = 1] = ...`
|
||||
// `[a]` in `[[a] = 1] = ...`
|
||||
// `a.b` in `[a.b = 1] = ...`
|
||||
// `a[0]` in `[a[0] = 1] = ...`
|
||||
return getTargetOfBindingOrAssignmentElement(<BindingOrAssignmentElement>bindingElement.left);
|
||||
}
|
||||
|
||||
if (isSpreadExpression(bindingElement)) {
|
||||
// `a` in `[...a] = ...`
|
||||
return getTargetOfBindingOrAssignmentElement(<BindingOrAssignmentElement>bindingElement.expression);
|
||||
}
|
||||
|
||||
// `a` in `[a] = ...`
|
||||
// `{a}` in `[{a}] = ...`
|
||||
// `[a]` in `[[a]] = ...`
|
||||
// `a.b` in `[a.b] = ...`
|
||||
// `a[0]` in `[a[0]] = ...`
|
||||
return bindingElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether an BindingOrAssignmentElement is a rest element.
|
||||
*/
|
||||
export function getRestIndicatorOfBindingOrAssignmentElement(bindingElement: BindingOrAssignmentElement): BindingOrAssignmentElementRestIndicator {
|
||||
switch (bindingElement.kind) {
|
||||
case SyntaxKind.Parameter:
|
||||
case SyntaxKind.BindingElement:
|
||||
// `...` in `let [...a] = ...`
|
||||
return (<ParameterDeclaration | BindingElement>bindingElement).dotDotDotToken;
|
||||
|
||||
case SyntaxKind.SpreadElement:
|
||||
case SyntaxKind.SpreadAssignment:
|
||||
// `...` in `[...a] = ...`
|
||||
return <SpreadElement | SpreadAssignment>bindingElement;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the property name of a BindingOrAssignmentElement
|
||||
*/
|
||||
export function getPropertyNameOfBindingOrAssignmentElement(bindingElement: BindingOrAssignmentElement) {
|
||||
switch (bindingElement.kind) {
|
||||
case SyntaxKind.BindingElement:
|
||||
// `a` in `let { a: b } = ...`
|
||||
// `[a]` in `let { [a]: b } = ...`
|
||||
// `"a"` in `let { "a": b } = ...`
|
||||
// `1` in `let { 1: b } = ...`
|
||||
if ((<BindingElement>bindingElement).propertyName) {
|
||||
const propertyName = (<BindingElement>bindingElement).propertyName;
|
||||
return isComputedPropertyName(propertyName) && isStringOrNumericLiteral(propertyName.expression)
|
||||
? propertyName.expression
|
||||
: propertyName;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
// `a` in `({ a: b } = ...)`
|
||||
// `[a]` in `({ [a]: b } = ...)`
|
||||
// `"a"` in `({ "a": b } = ...)`
|
||||
// `1` in `({ 1: b } = ...)`
|
||||
if ((<PropertyAssignment>bindingElement).name) {
|
||||
const propertyName = (<PropertyAssignment>bindingElement).name;
|
||||
return isComputedPropertyName(propertyName) && isStringOrNumericLiteral(propertyName.expression)
|
||||
? propertyName.expression
|
||||
: propertyName;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SyntaxKind.SpreadAssignment:
|
||||
// `a` in `({ ...a } = ...)`
|
||||
return (<SpreadAssignment>bindingElement).name;
|
||||
}
|
||||
|
||||
const target = getTargetOfBindingOrAssignmentElement(bindingElement);
|
||||
if (target && isPropertyName(target)) {
|
||||
return isComputedPropertyName(target) && isStringOrNumericLiteral(target.expression)
|
||||
? target.expression
|
||||
: target;
|
||||
}
|
||||
|
||||
Debug.fail("Invalid property name for binding element.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the elements of a BindingOrAssignmentPattern
|
||||
*/
|
||||
export function getElementsOfBindingOrAssignmentPattern(name: BindingOrAssignmentPattern): BindingOrAssignmentElement[] {
|
||||
switch (name.kind) {
|
||||
case SyntaxKind.ObjectBindingPattern:
|
||||
case SyntaxKind.ArrayBindingPattern:
|
||||
case SyntaxKind.ArrayLiteralExpression:
|
||||
// `a` in `{a}`
|
||||
// `a` in `[a]`
|
||||
return <BindingOrAssignmentElement[]>name.elements;
|
||||
|
||||
case SyntaxKind.ObjectLiteralExpression:
|
||||
// `a` in `{a}`
|
||||
return <BindingOrAssignmentElement[]>name.properties;
|
||||
}
|
||||
}
|
||||
|
||||
export function convertToArrayAssignmentElement(element: BindingOrAssignmentElement) {
|
||||
if (isBindingElement(element)) {
|
||||
if (element.dotDotDotToken) {
|
||||
Debug.assertNode(element.name, isIdentifier);
|
||||
return setOriginalNode(createSpread(<Identifier>element.name, element), element);
|
||||
}
|
||||
const expression = convertToAssignmentElementTarget(<ObjectBindingPattern | ArrayBindingPattern | Identifier>element.name);
|
||||
return element.initializer ? setOriginalNode(createAssignment(expression, element.initializer, element), element) : expression;
|
||||
}
|
||||
Debug.assertNode(element, isExpression);
|
||||
return <Expression>element;
|
||||
}
|
||||
|
||||
export function convertToObjectAssignmentElement(element: BindingOrAssignmentElement) {
|
||||
if (isBindingElement(element)) {
|
||||
if (element.dotDotDotToken) {
|
||||
Debug.assertNode(element.name, isIdentifier);
|
||||
return setOriginalNode(createSpreadAssignment(<Identifier>element.name, element), element);
|
||||
}
|
||||
if (element.propertyName) {
|
||||
const expression = convertToAssignmentElementTarget(<ObjectBindingPattern | ArrayBindingPattern | Identifier>element.name);
|
||||
return setOriginalNode(createPropertyAssignment(element.propertyName, element.initializer ? createAssignment(expression, element.initializer) : expression, element), element);
|
||||
}
|
||||
Debug.assertNode(element.name, isIdentifier);
|
||||
return setOriginalNode(createShorthandPropertyAssignment(<Identifier>element.name, element.initializer, element), element);
|
||||
}
|
||||
Debug.assertNode(element, isObjectLiteralElementLike);
|
||||
return <ObjectLiteralElementLike>element;
|
||||
}
|
||||
|
||||
export function convertToAssignmentPattern(node: BindingOrAssignmentPattern): AssignmentPattern {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ArrayBindingPattern:
|
||||
case SyntaxKind.ArrayLiteralExpression:
|
||||
return convertToArrayAssignmentPattern(node);
|
||||
|
||||
case SyntaxKind.ObjectBindingPattern:
|
||||
case SyntaxKind.ObjectLiteralExpression:
|
||||
return convertToObjectAssignmentPattern(node);
|
||||
}
|
||||
}
|
||||
|
||||
export function convertToObjectAssignmentPattern(node: ObjectBindingOrAssignmentPattern) {
|
||||
if (isObjectBindingPattern(node)) {
|
||||
return setOriginalNode(createObjectLiteral(map(node.elements, convertToObjectAssignmentElement), node), node);
|
||||
}
|
||||
Debug.assertNode(node, isObjectLiteralExpression);
|
||||
return <ObjectLiteralExpression>node;
|
||||
}
|
||||
|
||||
export function convertToArrayAssignmentPattern(node: ArrayBindingOrAssignmentPattern) {
|
||||
if (isArrayBindingPattern(node)) {
|
||||
return setOriginalNode(createArrayLiteral(map(node.elements, convertToArrayAssignmentElement), node), node);
|
||||
}
|
||||
Debug.assertNode(node, isArrayLiteralExpression);
|
||||
return <ArrayLiteralExpression>node;
|
||||
}
|
||||
|
||||
export function convertToAssignmentElementTarget(node: BindingOrAssignmentElementTarget): Expression {
|
||||
if (isBindingPattern(node)) {
|
||||
return convertToAssignmentPattern(node);
|
||||
}
|
||||
|
||||
Debug.assertNode(node, isExpression);
|
||||
return <Expression>node;
|
||||
}
|
||||
|
||||
export interface ExternalModuleInfo {
|
||||
externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[]; // imports of other external modules
|
||||
externalHelpersImportDeclaration: ImportDeclaration | undefined; // import of external helpers
|
||||
|
||||
+132
-127
@@ -14,6 +14,11 @@ namespace ts {
|
||||
return compilerOptions.traceResolution && host.trace !== undefined;
|
||||
}
|
||||
|
||||
/** Array that is only intended to be pushed to, never read. */
|
||||
interface Push<T> {
|
||||
push(value: T): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Result of trying to resolve a module.
|
||||
* At least one of `ts` and `js` should be defined, or the whole thing should be `undefined`.
|
||||
@@ -62,8 +67,7 @@ namespace ts {
|
||||
|
||||
interface ModuleResolutionState {
|
||||
host: ModuleResolutionHost;
|
||||
// We only use this subset of the compiler options.
|
||||
compilerOptions: { rootDirs?: string[], baseUrl?: string, paths?: MapLike<string[]> };
|
||||
compilerOptions: CompilerOptions;
|
||||
traceEnabled: boolean;
|
||||
}
|
||||
|
||||
@@ -128,7 +132,9 @@ namespace ts {
|
||||
currentDirectory = host.getCurrentDirectory();
|
||||
}
|
||||
|
||||
return currentDirectory !== undefined && getDefaultTypeRoots(currentDirectory, host);
|
||||
if (currentDirectory !== undefined) {
|
||||
return getDefaultTypeRoots(currentDirectory, host);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,20 +148,12 @@ namespace ts {
|
||||
}
|
||||
|
||||
let typeRoots: string[];
|
||||
|
||||
while (true) {
|
||||
const atTypes = combinePaths(currentDirectory, nodeModulesAtTypes);
|
||||
forEachAncestorDirectory(currentDirectory, directory => {
|
||||
const atTypes = combinePaths(directory, nodeModulesAtTypes);
|
||||
if (host.directoryExists(atTypes)) {
|
||||
(typeRoots || (typeRoots = [])).push(atTypes);
|
||||
}
|
||||
|
||||
const parent = getDirectoryPath(currentDirectory);
|
||||
if (parent === currentDirectory) {
|
||||
break;
|
||||
}
|
||||
currentDirectory = parent;
|
||||
}
|
||||
|
||||
});
|
||||
return typeRoots;
|
||||
}
|
||||
const nodeModulesAtTypes = combinePaths("node_modules", "@types");
|
||||
@@ -195,63 +193,66 @@ namespace ts {
|
||||
|
||||
const failedLookupLocations: string[] = [];
|
||||
|
||||
// Check primary library paths
|
||||
if (typeRoots && typeRoots.length) {
|
||||
let resolved = primaryLookup();
|
||||
let primary = true;
|
||||
if (!resolved) {
|
||||
resolved = secondaryLookup();
|
||||
primary = false;
|
||||
}
|
||||
|
||||
let resolvedTypeReferenceDirective: ResolvedTypeReferenceDirective | undefined;
|
||||
if (resolved) {
|
||||
resolved = realpath(resolved, host, traceEnabled);
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Resolving_with_primary_search_path_0, typeRoots.join(", "));
|
||||
trace(host, Diagnostics.Type_reference_directive_0_was_successfully_resolved_to_1_primary_Colon_2, typeReferenceDirectiveName, resolved, primary);
|
||||
}
|
||||
for (const typeRoot of typeRoots) {
|
||||
const candidate = combinePaths(typeRoot, typeReferenceDirectiveName);
|
||||
const candidateDirectory = getDirectoryPath(candidate);
|
||||
resolvedTypeReferenceDirective = { primary, resolvedFileName: resolved };
|
||||
}
|
||||
|
||||
const resolved = resolvedTypeScriptOnly(
|
||||
loadNodeModuleFromDirectory(Extensions.DtsOnly, candidate, failedLookupLocations,
|
||||
!directoryProbablyExists(candidateDirectory, host), moduleResolutionState));
|
||||
return { resolvedTypeReferenceDirective, failedLookupLocations };
|
||||
|
||||
if (resolved) {
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Type_reference_directive_0_was_successfully_resolved_to_1_primary_Colon_2, typeReferenceDirectiveName, resolved, true);
|
||||
}
|
||||
return {
|
||||
resolvedTypeReferenceDirective: { primary: true, resolvedFileName: resolved },
|
||||
failedLookupLocations
|
||||
};
|
||||
function primaryLookup(): string | undefined {
|
||||
// Check primary library paths
|
||||
if (typeRoots && typeRoots.length) {
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Resolving_with_primary_search_path_0, typeRoots.join(", "));
|
||||
}
|
||||
return forEach(typeRoots, typeRoot => {
|
||||
const candidate = combinePaths(typeRoot, typeReferenceDirectiveName);
|
||||
const candidateDirectory = getDirectoryPath(candidate);
|
||||
return resolvedTypeScriptOnly(
|
||||
loadNodeModuleFromDirectory(Extensions.DtsOnly, candidate, failedLookupLocations,
|
||||
!directoryProbablyExists(candidateDirectory, host), moduleResolutionState));
|
||||
});
|
||||
}
|
||||
else {
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Root_directory_cannot_be_determined_skipping_primary_search_paths);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Root_directory_cannot_be_determined_skipping_primary_search_paths);
|
||||
}
|
||||
}
|
||||
|
||||
let resolvedFile: string;
|
||||
const initialLocationForSecondaryLookup = containingFile && getDirectoryPath(containingFile);
|
||||
function secondaryLookup(): string | undefined {
|
||||
let resolvedFile: string;
|
||||
const initialLocationForSecondaryLookup = containingFile && getDirectoryPath(containingFile);
|
||||
|
||||
if (initialLocationForSecondaryLookup !== undefined) {
|
||||
// check secondary locations
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Looking_up_in_node_modules_folder_initial_location_0, initialLocationForSecondaryLookup);
|
||||
}
|
||||
resolvedFile = resolvedTypeScriptOnly(loadModuleFromNodeModules(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, failedLookupLocations, moduleResolutionState, /*checkOneLevel*/ false));
|
||||
if (traceEnabled) {
|
||||
if (resolvedFile) {
|
||||
trace(host, Diagnostics.Type_reference_directive_0_was_successfully_resolved_to_1_primary_Colon_2, typeReferenceDirectiveName, resolvedFile, false);
|
||||
if (initialLocationForSecondaryLookup !== undefined) {
|
||||
// check secondary locations
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Looking_up_in_node_modules_folder_initial_location_0, initialLocationForSecondaryLookup);
|
||||
}
|
||||
else {
|
||||
resolvedFile = resolvedTypeScriptOnly(loadModuleFromNodeModules(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, failedLookupLocations, moduleResolutionState));
|
||||
if (!resolvedFile && traceEnabled) {
|
||||
trace(host, Diagnostics.Type_reference_directive_0_was_not_resolved, typeReferenceDirectiveName);
|
||||
}
|
||||
return resolvedFile;
|
||||
}
|
||||
else {
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Containing_file_is_not_specified_and_root_directory_cannot_be_determined_skipping_lookup_in_node_modules_folder);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Containing_file_is_not_specified_and_root_directory_cannot_be_determined_skipping_lookup_in_node_modules_folder);
|
||||
}
|
||||
}
|
||||
return {
|
||||
resolvedTypeReferenceDirective: resolvedFile ? { primary: false, resolvedFileName: resolvedFile } : undefined,
|
||||
failedLookupLocations
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -341,7 +342,7 @@ namespace ts {
|
||||
* 'typings' entry or file 'index' with some supported extension
|
||||
* - Classic loader will only try to interpret '/a/b/c' as file.
|
||||
*/
|
||||
type ResolutionKindSpecificLoader = (extensions: Extensions, candidate: string, failedLookupLocations: string[], onlyRecordFailures: boolean, state: ModuleResolutionState) => Resolved | undefined;
|
||||
type ResolutionKindSpecificLoader = (extensions: Extensions, candidate: string, failedLookupLocations: Push<string>, onlyRecordFailures: boolean, state: ModuleResolutionState) => Resolved | undefined;
|
||||
|
||||
/**
|
||||
* Any module resolution kind can be augmented with optional settings: 'baseUrl', 'paths' and 'rootDirs' - they are used to
|
||||
@@ -404,7 +405,7 @@ namespace ts {
|
||||
* entries in 'rootDirs', use them to build absolute path out of (*) and try to resolve module from this location.
|
||||
*/
|
||||
function tryLoadModuleUsingOptionalResolutionSettings(extensions: Extensions, moduleName: string, containingDirectory: string, loader: ResolutionKindSpecificLoader,
|
||||
failedLookupLocations: string[], state: ModuleResolutionState): Resolved | undefined {
|
||||
failedLookupLocations: Push<string>, state: ModuleResolutionState): Resolved | undefined {
|
||||
|
||||
if (moduleHasNonRelativeName(moduleName)) {
|
||||
return tryLoadModuleUsingBaseUrl(extensions, moduleName, loader, failedLookupLocations, state);
|
||||
@@ -415,7 +416,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function tryLoadModuleUsingRootDirs(extensions: Extensions, moduleName: string, containingDirectory: string, loader: ResolutionKindSpecificLoader,
|
||||
failedLookupLocations: string[], state: ModuleResolutionState): Resolved | undefined {
|
||||
failedLookupLocations: Push<string>, state: ModuleResolutionState): Resolved | undefined {
|
||||
|
||||
if (!state.compilerOptions.rootDirs) {
|
||||
return undefined;
|
||||
@@ -491,7 +492,7 @@ namespace ts {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function tryLoadModuleUsingBaseUrl(extensions: Extensions, moduleName: string, loader: ResolutionKindSpecificLoader, failedLookupLocations: string[], state: ModuleResolutionState): Resolved | undefined {
|
||||
function tryLoadModuleUsingBaseUrl(extensions: Extensions, moduleName: string, loader: ResolutionKindSpecificLoader, failedLookupLocations: Push<string>, state: ModuleResolutionState): Resolved | undefined {
|
||||
if (!state.compilerOptions.baseUrl) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -514,18 +515,21 @@ namespace ts {
|
||||
if (state.traceEnabled) {
|
||||
trace(state.host, Diagnostics.Module_name_0_matched_pattern_1, moduleName, matchedPatternText);
|
||||
}
|
||||
for (const subst of state.compilerOptions.paths[matchedPatternText]) {
|
||||
return forEach(state.compilerOptions.paths[matchedPatternText], subst => {
|
||||
const path = matchedStar ? subst.replace("*", matchedStar) : subst;
|
||||
const candidate = normalizePath(combinePaths(state.compilerOptions.baseUrl, path));
|
||||
if (state.traceEnabled) {
|
||||
trace(state.host, Diagnostics.Trying_substitution_0_candidate_module_location_Colon_1, subst, path);
|
||||
}
|
||||
const resolved = loader(extensions, candidate, failedLookupLocations, !directoryProbablyExists(getDirectoryPath(candidate), state.host), state);
|
||||
if (resolved) {
|
||||
return resolved;
|
||||
// A path mapping may have a ".ts" extension; in contrast to an import, which should omit it.
|
||||
const tsExtension = tryGetExtensionFromPath(candidate);
|
||||
if (tsExtension !== undefined) {
|
||||
const path = tryFile(candidate, failedLookupLocations, /*onlyRecordFailures*/false, state);
|
||||
return path && { path, extension: tsExtension };
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
|
||||
return loader(extensions, candidate, failedLookupLocations, !directoryProbablyExists(getDirectoryPath(candidate), state.host), state);
|
||||
});
|
||||
}
|
||||
else {
|
||||
const candidate = normalizePath(combinePaths(state.compilerOptions.baseUrl, moduleName));
|
||||
@@ -548,7 +552,7 @@ namespace ts {
|
||||
const result = tryResolve(Extensions.TypeScript) || tryResolve(Extensions.JavaScript);
|
||||
if (result) {
|
||||
const { resolved, isExternalLibraryImport } = result;
|
||||
return createResolvedModuleWithFailedLookupLocations(resolved && resolvedWithRealpath(resolved, host, traceEnabled), isExternalLibraryImport, failedLookupLocations);
|
||||
return createResolvedModuleWithFailedLookupLocations(resolved, isExternalLibraryImport, failedLookupLocations);
|
||||
}
|
||||
return { resolvedModule: undefined, failedLookupLocations };
|
||||
|
||||
@@ -562,8 +566,9 @@ namespace ts {
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Loading_module_0_from_node_modules_folder, moduleName);
|
||||
}
|
||||
const resolved = loadModuleFromNodeModules(extensions, moduleName, containingDirectory, failedLookupLocations, state, /*checkOneLevel*/ false);
|
||||
return resolved && { resolved, isExternalLibraryImport: true };
|
||||
const resolved = loadModuleFromNodeModules(extensions, moduleName, containingDirectory, failedLookupLocations, state);
|
||||
// For node_modules lookups, get the real path so that multiple accesses to an `npm link`-ed module do not create duplicate files.
|
||||
return resolved && { resolved: { path: realpath(resolved.path, host, traceEnabled), extension: resolved.extension }, isExternalLibraryImport: true };
|
||||
}
|
||||
else {
|
||||
const candidate = normalizePath(combinePaths(containingDirectory, moduleName));
|
||||
@@ -573,19 +578,19 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function resolvedWithRealpath(resolved: Resolved, host: ModuleResolutionHost, traceEnabled: boolean): Resolved {
|
||||
function realpath(path: string, host: ModuleResolutionHost, traceEnabled: boolean): string {
|
||||
if (!host.realpath) {
|
||||
return resolved;
|
||||
return path;
|
||||
}
|
||||
|
||||
const real = normalizePath(host.realpath(resolved.path));
|
||||
const real = normalizePath(host.realpath(path));
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Resolving_real_path_for_0_result_1, resolved.path, real);
|
||||
trace(host, Diagnostics.Resolving_real_path_for_0_result_1, path, real);
|
||||
}
|
||||
return { path: real, extension: resolved.extension };
|
||||
return real;
|
||||
}
|
||||
|
||||
function nodeLoadModuleByRelativeName(extensions: Extensions, candidate: string, failedLookupLocations: string[], onlyRecordFailures: boolean, state: ModuleResolutionState): Resolved | undefined {
|
||||
function nodeLoadModuleByRelativeName(extensions: Extensions, candidate: string, failedLookupLocations: Push<string>, onlyRecordFailures: boolean, state: ModuleResolutionState): Resolved | undefined {
|
||||
if (state.traceEnabled) {
|
||||
trace(state.host, Diagnostics.Loading_module_as_file_Slash_folder_candidate_module_location_0, candidate);
|
||||
}
|
||||
@@ -604,7 +609,7 @@ namespace ts {
|
||||
* @param {boolean} onlyRecordFailures - if true then function won't try to actually load files but instead record all attempts as failures. This flag is necessary
|
||||
* in cases when we know upfront that all load attempts will fail (because containing folder does not exists) however we still need to record all failed lookup locations.
|
||||
*/
|
||||
function loadModuleFromFile(extensions: Extensions, candidate: string, failedLookupLocations: string[], onlyRecordFailures: boolean, state: ModuleResolutionState): Resolved | undefined {
|
||||
function loadModuleFromFile(extensions: Extensions, candidate: string, failedLookupLocations: Push<string>, onlyRecordFailures: boolean, state: ModuleResolutionState): Resolved | undefined {
|
||||
// First, try adding an extension. An import of "foo" could be matched by a file "foo.ts", or "foo.js" by "foo.js.ts"
|
||||
const resolvedByAddingExtension = tryAddingExtensions(candidate, extensions, failedLookupLocations, onlyRecordFailures, state);
|
||||
if (resolvedByAddingExtension) {
|
||||
@@ -624,7 +629,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
/** Try to return an existing file that adds one of the `extensions` to `candidate`. */
|
||||
function tryAddingExtensions(candidate: string, extensions: Extensions, failedLookupLocations: string[], onlyRecordFailures: boolean, state: ModuleResolutionState): Resolved | undefined {
|
||||
function tryAddingExtensions(candidate: string, extensions: Extensions, failedLookupLocations: Push<string>, onlyRecordFailures: boolean, state: ModuleResolutionState): Resolved | undefined {
|
||||
if (!onlyRecordFailures) {
|
||||
// check if containing folder exists - if it doesn't then just record failures for all supported extensions without disk probing
|
||||
const directory = getDirectoryPath(candidate);
|
||||
@@ -649,7 +654,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
/** Return the file if it exists. */
|
||||
function tryFile(fileName: string, failedLookupLocation: string[], onlyRecordFailures: boolean, state: ModuleResolutionState): string | undefined {
|
||||
function tryFile(fileName: string, failedLookupLocations: Push<string>, onlyRecordFailures: boolean, state: ModuleResolutionState): string | undefined {
|
||||
if (!onlyRecordFailures && state.host.fileExists(fileName)) {
|
||||
if (state.traceEnabled) {
|
||||
trace(state.host, Diagnostics.File_0_exist_use_it_as_a_name_resolution_result, fileName);
|
||||
@@ -660,12 +665,12 @@ namespace ts {
|
||||
if (state.traceEnabled) {
|
||||
trace(state.host, Diagnostics.File_0_does_not_exist, fileName);
|
||||
}
|
||||
failedLookupLocation.push(fileName);
|
||||
failedLookupLocations.push(fileName);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function loadNodeModuleFromDirectory(extensions: Extensions, candidate: string, failedLookupLocation: string[], onlyRecordFailures: boolean, state: ModuleResolutionState): Resolved | undefined {
|
||||
function loadNodeModuleFromDirectory(extensions: Extensions, candidate: string, failedLookupLocations: Push<string>, onlyRecordFailures: boolean, state: ModuleResolutionState): Resolved | undefined {
|
||||
const packageJsonPath = pathToPackageJson(candidate);
|
||||
const directoryExists = !onlyRecordFailures && directoryProbablyExists(candidate, state.host);
|
||||
|
||||
@@ -677,12 +682,12 @@ namespace ts {
|
||||
if (typesFile) {
|
||||
const onlyRecordFailures = !directoryProbablyExists(getDirectoryPath(typesFile), state.host);
|
||||
// A package.json "typings" may specify an exact filename, or may choose to omit an extension.
|
||||
const fromFile = tryFile(typesFile, failedLookupLocation, onlyRecordFailures, state);
|
||||
const fromFile = tryFile(typesFile, failedLookupLocations, onlyRecordFailures, state);
|
||||
if (fromFile) {
|
||||
// Note: this would allow a package.json to specify a ".js" file as typings. Maybe that should be forbidden.
|
||||
return resolvedFromAnyFile(fromFile);
|
||||
}
|
||||
const x = tryAddingExtensions(typesFile, Extensions.TypeScript, failedLookupLocation, onlyRecordFailures, state);
|
||||
const x = tryAddingExtensions(typesFile, Extensions.TypeScript, failedLookupLocations, onlyRecordFailures, state);
|
||||
if (x) {
|
||||
return x;
|
||||
}
|
||||
@@ -698,17 +703,17 @@ namespace ts {
|
||||
trace(state.host, Diagnostics.File_0_does_not_exist, packageJsonPath);
|
||||
}
|
||||
// record package json as one of failed lookup locations - in the future if this file will appear it will invalidate resolution results
|
||||
failedLookupLocation.push(packageJsonPath);
|
||||
failedLookupLocations.push(packageJsonPath);
|
||||
}
|
||||
|
||||
return loadModuleFromFile(extensions, combinePaths(candidate, "index"), failedLookupLocation, !directoryExists, state);
|
||||
return loadModuleFromFile(extensions, combinePaths(candidate, "index"), failedLookupLocations, !directoryExists, state);
|
||||
}
|
||||
|
||||
function pathToPackageJson(directory: string): string {
|
||||
return combinePaths(directory, "package.json");
|
||||
}
|
||||
|
||||
function loadModuleFromNodeModulesFolder(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: string[], state: ModuleResolutionState): Resolved | undefined {
|
||||
function loadModuleFromNodeModulesFolder(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: Push<string>, state: ModuleResolutionState): Resolved | undefined {
|
||||
const nodeModulesFolder = combinePaths(directory, "node_modules");
|
||||
const nodeModulesFolderExists = directoryProbablyExists(nodeModulesFolder, state.host);
|
||||
const candidate = normalizePath(combinePaths(nodeModulesFolder, moduleName));
|
||||
@@ -717,34 +722,30 @@ namespace ts {
|
||||
loadNodeModuleFromDirectory(extensions, candidate, failedLookupLocations, !nodeModulesFolderExists, state);
|
||||
}
|
||||
|
||||
function loadModuleFromNodeModules(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: string[], state: ModuleResolutionState, checkOneLevel: boolean): Resolved | undefined {
|
||||
return loadModuleFromNodeModulesWorker(extensions, moduleName, directory, failedLookupLocations, state, checkOneLevel, /*typesOnly*/ false);
|
||||
function loadModuleFromNodeModules(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: Push<string>, state: ModuleResolutionState): Resolved | undefined {
|
||||
return loadModuleFromNodeModulesWorker(extensions, moduleName, directory, failedLookupLocations, state, /*typesOnly*/ false);
|
||||
}
|
||||
function loadModuleFromNodeModulesAtTypes(moduleName: string, directory: string, failedLookupLocations: string[], state: ModuleResolutionState): Resolved | undefined {
|
||||
return loadModuleFromNodeModulesWorker(Extensions.TypeScript, moduleName, directory, failedLookupLocations, state, /*checkOneLevel*/ false, /*typesOnly*/ true);
|
||||
function loadModuleFromNodeModulesAtTypes(moduleName: string, directory: string, failedLookupLocations: Push<string>, state: ModuleResolutionState): Resolved | undefined {
|
||||
// Extensions parameter here doesn't actually matter, because typesOnly ensures we're just doing @types lookup, which is always DtsOnly.
|
||||
return loadModuleFromNodeModulesWorker(Extensions.DtsOnly, moduleName, directory, failedLookupLocations, state, /*typesOnly*/ true);
|
||||
}
|
||||
|
||||
function loadModuleFromNodeModulesWorker(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: string[], state: ModuleResolutionState, checkOneLevel: boolean, typesOnly: boolean): Resolved | undefined {
|
||||
directory = normalizeSlashes(directory);
|
||||
while (true) {
|
||||
if (getBaseFileName(directory) !== "node_modules") {
|
||||
const resolved = tryInDirectory();
|
||||
if (resolved) {
|
||||
return resolved;
|
||||
}
|
||||
function loadModuleFromNodeModulesWorker(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: Push<string>, state: ModuleResolutionState, typesOnly: boolean): Resolved | undefined {
|
||||
return forEachAncestorDirectory(normalizeSlashes(directory), ancestorDirectory => {
|
||||
if (getBaseFileName(ancestorDirectory) !== "node_modules") {
|
||||
return loadModuleFromNodeModulesOneLevel(extensions, moduleName, ancestorDirectory, failedLookupLocations, state, typesOnly);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const parentPath = getDirectoryPath(directory);
|
||||
if (parentPath === directory || checkOneLevel) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
directory = parentPath;
|
||||
/** Load a module from a single node_modules directory, but not from any ancestors' node_modules directories. */
|
||||
function loadModuleFromNodeModulesOneLevel(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: Push<string>, state: ModuleResolutionState, typesOnly = false): Resolved | undefined {
|
||||
const packageResult = typesOnly ? undefined : loadModuleFromNodeModulesFolder(extensions, moduleName, directory, failedLookupLocations, state);
|
||||
if (packageResult) {
|
||||
return packageResult;
|
||||
}
|
||||
|
||||
function tryInDirectory(): Resolved | undefined {
|
||||
const packageResult = typesOnly ? undefined : loadModuleFromNodeModulesFolder(extensions, moduleName, directory, failedLookupLocations, state);
|
||||
return packageResult || loadModuleFromNodeModulesFolder(extensions, combinePaths("@types", moduleName), directory, failedLookupLocations, state);
|
||||
if (extensions !== Extensions.JavaScript) {
|
||||
return loadModuleFromNodeModulesFolder(Extensions.DtsOnly, combinePaths("@types", moduleName), directory, failedLookupLocations, state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -764,7 +765,11 @@ namespace ts {
|
||||
}
|
||||
|
||||
if (moduleHasNonRelativeName(moduleName)) {
|
||||
const resolved = loadModuleFromAncestorDirectories(extensions, moduleName, containingDirectory, failedLookupLocations, state);
|
||||
// Climb up parent directories looking for a module.
|
||||
const resolved = forEachAncestorDirectory(containingDirectory, directory => {
|
||||
const searchName = normalizePath(combinePaths(directory, moduleName));
|
||||
return loadModuleFromFile(extensions, searchName, failedLookupLocations, /*onlyRecordFailures*/ false, state);
|
||||
});
|
||||
if (resolved) {
|
||||
return resolved;
|
||||
}
|
||||
@@ -780,22 +785,6 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
/** Climb up parent directories looking for a module. */
|
||||
function loadModuleFromAncestorDirectories(extensions: Extensions, moduleName: string, containingDirectory: string, failedLookupLocations: string[], state: ModuleResolutionState): Resolved | undefined {
|
||||
while (true) {
|
||||
const searchName = normalizePath(combinePaths(containingDirectory, moduleName));
|
||||
const referencedSourceFile = loadModuleFromFile(extensions, searchName, failedLookupLocations, /*onlyRecordFailures*/ false, state);
|
||||
if (referencedSourceFile) {
|
||||
return referencedSourceFile;
|
||||
}
|
||||
const parentPath = getDirectoryPath(containingDirectory);
|
||||
if (parentPath === containingDirectory) {
|
||||
return undefined;
|
||||
}
|
||||
containingDirectory = parentPath;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* LSHost may load a module from a global cache of typings.
|
||||
* This is the minumum code needed to expose that functionality; the rest is in LSHost.
|
||||
@@ -808,8 +797,24 @@ namespace ts {
|
||||
}
|
||||
const state: ModuleResolutionState = { compilerOptions, host, traceEnabled };
|
||||
const failedLookupLocations: string[] = [];
|
||||
const resolved = loadModuleFromNodeModules(Extensions.TypeScript, moduleName, globalCache, failedLookupLocations, state, /*checkOneLevel*/ true) ||
|
||||
loadModuleFromNodeModules(Extensions.JavaScript, moduleName, globalCache, failedLookupLocations, state, /*checkOneLevel*/ true);
|
||||
const resolved = loadModuleFromNodeModulesOneLevel(Extensions.DtsOnly, moduleName, globalCache, failedLookupLocations, state);
|
||||
return createResolvedModuleWithFailedLookupLocations(resolved, /*isExternalLibraryImport*/ true, failedLookupLocations);
|
||||
}
|
||||
|
||||
/** Calls `callback` on `directory` and every ancestor directory it has, returning the first defined result. */
|
||||
function forEachAncestorDirectory<T>(directory: string, callback: (directory: string) => T | undefined): T | undefined {
|
||||
while (true) {
|
||||
const result = callback(directory);
|
||||
if (result !== undefined) {
|
||||
return result;
|
||||
}
|
||||
|
||||
const parentPath = getDirectoryPath(directory);
|
||||
if (parentPath === directory) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
directory = parentPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
+75
-8
@@ -74,6 +74,8 @@ namespace ts {
|
||||
visitNode(cbNode, (<ShorthandPropertyAssignment>node).questionToken) ||
|
||||
visitNode(cbNode, (<ShorthandPropertyAssignment>node).equalsToken) ||
|
||||
visitNode(cbNode, (<ShorthandPropertyAssignment>node).objectAssignmentInitializer);
|
||||
case SyntaxKind.SpreadAssignment:
|
||||
return visitNode(cbNode, (<SpreadAssignment>node).expression);
|
||||
case SyntaxKind.Parameter:
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
case SyntaxKind.PropertySignature:
|
||||
@@ -139,6 +141,11 @@ namespace ts {
|
||||
case SyntaxKind.IndexedAccessType:
|
||||
return visitNode(cbNode, (<IndexedAccessTypeNode>node).objectType) ||
|
||||
visitNode(cbNode, (<IndexedAccessTypeNode>node).indexType);
|
||||
case SyntaxKind.MappedType:
|
||||
return visitNode(cbNode, (<MappedTypeNode>node).readonlyToken) ||
|
||||
visitNode(cbNode, (<MappedTypeNode>node).typeParameter) ||
|
||||
visitNode(cbNode, (<MappedTypeNode>node).questionToken) ||
|
||||
visitNode(cbNode, (<MappedTypeNode>node).type);
|
||||
case SyntaxKind.LiteralType:
|
||||
return visitNode(cbNode, (<LiteralTypeNode>node).literal);
|
||||
case SyntaxKind.ObjectBindingPattern:
|
||||
@@ -197,8 +204,8 @@ namespace ts {
|
||||
visitNode(cbNode, (<ConditionalExpression>node).whenTrue) ||
|
||||
visitNode(cbNode, (<ConditionalExpression>node).colonToken) ||
|
||||
visitNode(cbNode, (<ConditionalExpression>node).whenFalse);
|
||||
case SyntaxKind.SpreadElementExpression:
|
||||
return visitNode(cbNode, (<SpreadElementExpression>node).expression);
|
||||
case SyntaxKind.SpreadElement:
|
||||
return visitNode(cbNode, (<SpreadElement>node).expression);
|
||||
case SyntaxKind.Block:
|
||||
case SyntaxKind.ModuleBlock:
|
||||
return visitNodes(cbNodes, (<Block>node).statements);
|
||||
@@ -439,6 +446,10 @@ namespace ts {
|
||||
return result;
|
||||
}
|
||||
|
||||
export function parseIsolatedEntityName(text: string, languageVersion: ScriptTarget): EntityName {
|
||||
return Parser.parseIsolatedEntityName(text, languageVersion);
|
||||
}
|
||||
|
||||
export function isExternalModule(file: SourceFile): boolean {
|
||||
return file.externalModuleIndicator !== undefined;
|
||||
}
|
||||
@@ -590,6 +601,16 @@ namespace ts {
|
||||
return result;
|
||||
}
|
||||
|
||||
export function parseIsolatedEntityName(content: string, languageVersion: ScriptTarget): EntityName {
|
||||
initializeState(content, languageVersion, /*syntaxCursor*/ undefined, ScriptKind.JS);
|
||||
// Prime the scanner.
|
||||
nextToken();
|
||||
const entityName = parseEntityName(/*allowReservedWords*/ true);
|
||||
const isInvalid = token() === SyntaxKind.EndOfFileToken && !parseDiagnostics.length;
|
||||
clearState();
|
||||
return isInvalid ? entityName : undefined;
|
||||
}
|
||||
|
||||
function getLanguageVariant(scriptKind: ScriptKind) {
|
||||
// .tsx and .jsx files are treated as jsx language variant.
|
||||
return scriptKind === ScriptKind.TSX || scriptKind === ScriptKind.JSX || scriptKind === ScriptKind.JS ? LanguageVariant.JSX : LanguageVariant.Standard;
|
||||
@@ -1148,7 +1169,7 @@ namespace ts {
|
||||
|
||||
function parsePropertyNameWorker(allowComputedPropertyNames: boolean): PropertyName {
|
||||
if (token() === SyntaxKind.StringLiteral || token() === SyntaxKind.NumericLiteral) {
|
||||
return parseLiteralNode(/*internName*/ true);
|
||||
return <StringLiteral | NumericLiteral>parseLiteralNode(/*internName*/ true);
|
||||
}
|
||||
if (allowComputedPropertyNames && token() === SyntaxKind.OpenBracketToken) {
|
||||
return parseComputedPropertyName();
|
||||
@@ -1270,9 +1291,11 @@ namespace ts {
|
||||
// which would be a candidate for improved error reporting.
|
||||
return token() === SyntaxKind.OpenBracketToken || isLiteralPropertyName();
|
||||
case ParsingContext.ObjectLiteralMembers:
|
||||
return token() === SyntaxKind.OpenBracketToken || token() === SyntaxKind.AsteriskToken || isLiteralPropertyName();
|
||||
return token() === SyntaxKind.OpenBracketToken || token() === SyntaxKind.AsteriskToken || token() === SyntaxKind.DotDotDotToken || isLiteralPropertyName();
|
||||
case ParsingContext.RestProperties:
|
||||
return isLiteralPropertyName();
|
||||
case ParsingContext.ObjectBindingElements:
|
||||
return token() === SyntaxKind.OpenBracketToken || isLiteralPropertyName();
|
||||
return token() === SyntaxKind.OpenBracketToken || token() === SyntaxKind.DotDotDotToken || isLiteralPropertyName();
|
||||
case ParsingContext.HeritageClauseElement:
|
||||
// If we see { } then only consume it as an expression if it is followed by , or {
|
||||
// That way we won't consume the body of a class in its heritage clause.
|
||||
@@ -1399,6 +1422,7 @@ namespace ts {
|
||||
case ParsingContext.ArrayBindingElements:
|
||||
return token() === SyntaxKind.CloseBracketToken;
|
||||
case ParsingContext.Parameters:
|
||||
case ParsingContext.RestProperties:
|
||||
// Tokens other than ')' and ']' (the latter for index signatures) are here for better error recovery
|
||||
return token() === SyntaxKind.CloseParenToken || token() === SyntaxKind.CloseBracketToken /*|| token === SyntaxKind.OpenBraceToken*/;
|
||||
case ParsingContext.TypeArguments:
|
||||
@@ -1584,6 +1608,9 @@ namespace ts {
|
||||
case ParsingContext.Parameters:
|
||||
return isReusableParameter(node);
|
||||
|
||||
case ParsingContext.RestProperties:
|
||||
return false;
|
||||
|
||||
// Any other lists we do not care about reusing nodes in. But feel free to add if
|
||||
// you can do so safely. Danger areas involve nodes that may involve speculative
|
||||
// parsing. If speculative parsing is involved with the node, then the range the
|
||||
@@ -1781,6 +1808,7 @@ namespace ts {
|
||||
case ParsingContext.BlockStatements: return Diagnostics.Declaration_or_statement_expected;
|
||||
case ParsingContext.SwitchClauses: return Diagnostics.case_or_default_expected;
|
||||
case ParsingContext.SwitchClauseStatements: return Diagnostics.Statement_expected;
|
||||
case ParsingContext.RestProperties: // fallthrough
|
||||
case ParsingContext.TypeMembers: return Diagnostics.Property_or_signature_expected;
|
||||
case ParsingContext.ClassMembers: return Diagnostics.Unexpected_token_A_constructor_method_accessor_or_property_was_expected;
|
||||
case ParsingContext.EnumMembers: return Diagnostics.Enum_member_expected;
|
||||
@@ -2400,6 +2428,36 @@ namespace ts {
|
||||
return members;
|
||||
}
|
||||
|
||||
function isStartOfMappedType() {
|
||||
nextToken();
|
||||
if (token() === SyntaxKind.ReadonlyKeyword) {
|
||||
nextToken();
|
||||
}
|
||||
return token() === SyntaxKind.OpenBracketToken && nextTokenIsIdentifier() && nextToken() === SyntaxKind.InKeyword;
|
||||
}
|
||||
|
||||
function parseMappedTypeParameter() {
|
||||
const node = <TypeParameterDeclaration>createNode(SyntaxKind.TypeParameter);
|
||||
node.name = parseIdentifier();
|
||||
parseExpected(SyntaxKind.InKeyword);
|
||||
node.constraint = parseType();
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
function parseMappedType() {
|
||||
const node = <MappedTypeNode>createNode(SyntaxKind.MappedType);
|
||||
parseExpected(SyntaxKind.OpenBraceToken);
|
||||
node.readonlyToken = parseOptionalToken(SyntaxKind.ReadonlyKeyword);
|
||||
parseExpected(SyntaxKind.OpenBracketToken);
|
||||
node.typeParameter = parseMappedTypeParameter();
|
||||
parseExpected(SyntaxKind.CloseBracketToken);
|
||||
node.questionToken = parseOptionalToken(SyntaxKind.QuestionToken);
|
||||
node.type = parseTypeAnnotation();
|
||||
parseSemicolon();
|
||||
parseExpected(SyntaxKind.CloseBraceToken);
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
function parseTupleType(): TupleTypeNode {
|
||||
const node = <TupleTypeNode>createNode(SyntaxKind.TupleType);
|
||||
node.elementTypes = parseBracketedList(ParsingContext.TupleElementTypes, parseType, SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken);
|
||||
@@ -2473,7 +2531,7 @@ namespace ts {
|
||||
case SyntaxKind.TypeOfKeyword:
|
||||
return parseTypeQuery();
|
||||
case SyntaxKind.OpenBraceToken:
|
||||
return parseTypeLiteral();
|
||||
return lookAhead(isStartOfMappedType) ? parseMappedType() : parseTypeLiteral();
|
||||
case SyntaxKind.OpenBracketToken:
|
||||
return parseTupleType();
|
||||
case SyntaxKind.OpenParenToken:
|
||||
@@ -4123,7 +4181,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function parseSpreadElement(): Expression {
|
||||
const node = <SpreadElementExpression>createNode(SyntaxKind.SpreadElementExpression);
|
||||
const node = <SpreadElement>createNode(SyntaxKind.SpreadElement);
|
||||
parseExpected(SyntaxKind.DotDotDotToken);
|
||||
node.expression = parseAssignmentExpressionOrHigher();
|
||||
return finishNode(node);
|
||||
@@ -4163,6 +4221,12 @@ namespace ts {
|
||||
|
||||
function parseObjectLiteralElement(): ObjectLiteralElementLike {
|
||||
const fullStart = scanner.getStartPos();
|
||||
const dotDotDotToken = parseOptionalToken(SyntaxKind.DotDotDotToken);
|
||||
if (dotDotDotToken) {
|
||||
const spreadElement = <SpreadAssignment>createNode(SyntaxKind.SpreadAssignment, fullStart);
|
||||
spreadElement.expression = parseAssignmentExpressionOrHigher();
|
||||
return addJSDocComment(finishNode(spreadElement));
|
||||
}
|
||||
const decorators = parseDecorators();
|
||||
const modifiers = parseModifiers();
|
||||
|
||||
@@ -4868,6 +4932,7 @@ namespace ts {
|
||||
|
||||
function parseObjectBindingElement(): BindingElement {
|
||||
const node = <BindingElement>createNode(SyntaxKind.BindingElement);
|
||||
node.dotDotDotToken = parseOptionalToken(SyntaxKind.DotDotDotToken);
|
||||
const tokenIsIdentifier = isIdentifier();
|
||||
const propertyName = parsePropertyName();
|
||||
if (tokenIsIdentifier && token() !== SyntaxKind.ColonToken) {
|
||||
@@ -5452,7 +5517,7 @@ namespace ts {
|
||||
node.flags |= NodeFlags.GlobalAugmentation;
|
||||
}
|
||||
else {
|
||||
node.name = parseLiteralNode(/*internName*/ true);
|
||||
node.name = <StringLiteral>parseLiteralNode(/*internName*/ true);
|
||||
}
|
||||
|
||||
if (token() === SyntaxKind.OpenBraceToken) {
|
||||
@@ -5812,6 +5877,7 @@ namespace ts {
|
||||
JsxChildren, // Things between opening and closing JSX tags
|
||||
ArrayLiteralMembers, // Members in array literal
|
||||
Parameters, // Parameters in parameter list
|
||||
RestProperties, // Property names in a rest type list
|
||||
TypeParameters, // Type parameters in type parameter list
|
||||
TypeArguments, // Type arguments in type argument list
|
||||
TupleElementTypes, // Element types in tuple element type list
|
||||
@@ -6241,6 +6307,7 @@ namespace ts {
|
||||
}
|
||||
if (token() === SyntaxKind.NewLineTrivia) {
|
||||
state = JSDocState.BeginningOfLine;
|
||||
indent = 0;
|
||||
nextJSDocToken();
|
||||
}
|
||||
while (token() !== SyntaxKind.EndOfFileToken) {
|
||||
|
||||
+189
-178
@@ -3,10 +3,6 @@
|
||||
/// <reference path="core.ts" />
|
||||
|
||||
namespace ts {
|
||||
/** The version of the TypeScript compiler release */
|
||||
|
||||
export const version = "2.1.0";
|
||||
|
||||
const emptyArray: any[] = [];
|
||||
|
||||
export function findConfigFile(searchPath: string, fileExists: (fileName: string) => boolean, configName = "tsconfig.json"): string {
|
||||
@@ -431,13 +427,14 @@ namespace ts {
|
||||
return program;
|
||||
|
||||
function getCommonSourceDirectory() {
|
||||
if (typeof commonSourceDirectory === "undefined") {
|
||||
if (options.rootDir && checkSourceFilesBelongToPath(files, options.rootDir)) {
|
||||
if (commonSourceDirectory === undefined) {
|
||||
const emittedFiles = filterSourceFilesInDirectory(files, isSourceFileFromExternalLibrary);
|
||||
if (options.rootDir && checkSourceFilesBelongToPath(emittedFiles, options.rootDir)) {
|
||||
// If a rootDir is specified and is valid use it as the commonSourceDirectory
|
||||
commonSourceDirectory = getNormalizedAbsolutePath(options.rootDir, currentDirectory);
|
||||
}
|
||||
else {
|
||||
commonSourceDirectory = computeCommonSourceDirectory(files);
|
||||
commonSourceDirectory = computeCommonSourceDirectory(emittedFiles);
|
||||
}
|
||||
if (commonSourceDirectory && commonSourceDirectory[commonSourceDirectory.length - 1] !== directorySeparator) {
|
||||
// Make sure directory path ends with directory separator so this string can directly
|
||||
@@ -476,7 +473,7 @@ namespace ts {
|
||||
return resolveModuleNamesWorker(moduleNames, containingFile);
|
||||
}
|
||||
|
||||
// at this point we know that either
|
||||
// at this point we know that either
|
||||
// - file has local declarations for ambient modules
|
||||
// OR
|
||||
// - old program state is available
|
||||
@@ -670,7 +667,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
const modifiedFilePaths = modifiedSourceFiles.map(f => f.newFile.path);
|
||||
// try to verify results of module resolution
|
||||
// try to verify results of module resolution
|
||||
for (const { oldFile: oldSourceFile, newFile: newSourceFile } of modifiedSourceFiles) {
|
||||
const newSourceFilePath = getNormalizedAbsolutePath(newSourceFile.fileName, currentDirectory);
|
||||
if (resolveModuleNamesWorker) {
|
||||
@@ -908,48 +905,24 @@ namespace ts {
|
||||
function getJavaScriptSyntacticDiagnosticsForFile(sourceFile: SourceFile): Diagnostic[] {
|
||||
return runWithCancellationToken(() => {
|
||||
const diagnostics: Diagnostic[] = [];
|
||||
let parent: Node = sourceFile;
|
||||
walk(sourceFile);
|
||||
|
||||
return diagnostics;
|
||||
|
||||
function walk(node: Node): boolean {
|
||||
if (!node) {
|
||||
return false;
|
||||
}
|
||||
function walk(node: Node) {
|
||||
// Return directly from the case if the given node doesnt want to visit each child
|
||||
// Otherwise break to visit each child
|
||||
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
diagnostics.push(createDiagnosticForNode(node, Diagnostics.import_can_only_be_used_in_a_ts_file));
|
||||
return true;
|
||||
case SyntaxKind.ExportAssignment:
|
||||
if ((<ExportAssignment>node).isExportEquals) {
|
||||
diagnostics.push(createDiagnosticForNode(node, Diagnostics.export_can_only_be_used_in_a_ts_file));
|
||||
return true;
|
||||
switch (parent.kind) {
|
||||
case SyntaxKind.Parameter:
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
if ((<ParameterDeclaration | PropertyDeclaration>parent).questionToken === node) {
|
||||
diagnostics.push(createDiagnosticForNode(node, Diagnostics._0_can_only_be_used_in_a_ts_file, "?"));
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
let classDeclaration = <ClassDeclaration>node;
|
||||
if (checkModifiers(classDeclaration.modifiers) ||
|
||||
checkTypeParameters(classDeclaration.typeParameters)) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.HeritageClause:
|
||||
let heritageClause = <HeritageClause>node;
|
||||
if (heritageClause.token === SyntaxKind.ImplementsKeyword) {
|
||||
diagnostics.push(createDiagnosticForNode(node, Diagnostics.implements_clauses_can_only_be_used_in_a_ts_file));
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
diagnostics.push(createDiagnosticForNode(node, Diagnostics.interface_declarations_can_only_be_used_in_a_ts_file));
|
||||
return true;
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
diagnostics.push(createDiagnosticForNode(node, Diagnostics.module_declarations_can_only_be_used_in_a_ts_file));
|
||||
return true;
|
||||
case SyntaxKind.TypeAliasDeclaration:
|
||||
diagnostics.push(createDiagnosticForNode(node, Diagnostics.type_aliases_can_only_be_used_in_a_ts_file));
|
||||
return true;
|
||||
|
||||
// Pass through
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.MethodSignature:
|
||||
case SyntaxKind.Constructor:
|
||||
@@ -959,124 +932,151 @@ namespace ts {
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
const functionDeclaration = <FunctionLikeDeclaration>node;
|
||||
if (checkModifiers(functionDeclaration.modifiers) ||
|
||||
checkTypeParameters(functionDeclaration.typeParameters) ||
|
||||
checkTypeAnnotation(functionDeclaration.type)) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.VariableStatement:
|
||||
const variableStatement = <VariableStatement>node;
|
||||
if (checkModifiers(variableStatement.modifiers)) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
const variableDeclaration = <VariableDeclaration>node;
|
||||
if (checkTypeAnnotation(variableDeclaration.type)) {
|
||||
return true;
|
||||
// type annotation
|
||||
if ((<FunctionLikeDeclaration | VariableDeclaration | ParameterDeclaration | PropertyDeclaration>parent).type === node) {
|
||||
diagnostics.push(createDiagnosticForNode(node, Diagnostics.types_can_only_be_used_in_a_ts_file));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
diagnostics.push(createDiagnosticForNode(node, Diagnostics.import_can_only_be_used_in_a_ts_file));
|
||||
return;
|
||||
case SyntaxKind.ExportAssignment:
|
||||
if ((<ExportAssignment>node).isExportEquals) {
|
||||
diagnostics.push(createDiagnosticForNode(node, Diagnostics.export_can_only_be_used_in_a_ts_file));
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.HeritageClause:
|
||||
let heritageClause = <HeritageClause>node;
|
||||
if (heritageClause.token === SyntaxKind.ImplementsKeyword) {
|
||||
diagnostics.push(createDiagnosticForNode(node, Diagnostics.implements_clauses_can_only_be_used_in_a_ts_file));
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
diagnostics.push(createDiagnosticForNode(node, Diagnostics.interface_declarations_can_only_be_used_in_a_ts_file));
|
||||
return;
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
diagnostics.push(createDiagnosticForNode(node, Diagnostics.module_declarations_can_only_be_used_in_a_ts_file));
|
||||
return;
|
||||
case SyntaxKind.TypeAliasDeclaration:
|
||||
diagnostics.push(createDiagnosticForNode(node, Diagnostics.type_aliases_can_only_be_used_in_a_ts_file));
|
||||
return;
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
diagnostics.push(createDiagnosticForNode(node, Diagnostics.enum_declarations_can_only_be_used_in_a_ts_file));
|
||||
return;
|
||||
case SyntaxKind.TypeAssertionExpression:
|
||||
let typeAssertionExpression = <TypeAssertion>node;
|
||||
diagnostics.push(createDiagnosticForNode(typeAssertionExpression.type, Diagnostics.type_assertion_expressions_can_only_be_used_in_a_ts_file));
|
||||
return;
|
||||
}
|
||||
|
||||
const prevParent = parent;
|
||||
parent = node;
|
||||
forEachChild(node, walk, walkArray);
|
||||
parent = prevParent;
|
||||
}
|
||||
|
||||
function walkArray(nodes: NodeArray<Node>) {
|
||||
if (parent.decorators === nodes && !options.experimentalDecorators) {
|
||||
diagnostics.push(createDiagnosticForNode(parent, 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));
|
||||
}
|
||||
|
||||
switch (parent.kind) {
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.MethodSignature:
|
||||
case SyntaxKind.Constructor:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
// Check type parameters
|
||||
if (nodes === (<ClassDeclaration | FunctionLikeDeclaration>parent).typeParameters) {
|
||||
diagnostics.push(createDiagnosticForNodeArray(nodes, Diagnostics.type_parameter_declarations_can_only_be_used_in_a_ts_file));
|
||||
return;
|
||||
}
|
||||
// pass through
|
||||
case SyntaxKind.VariableStatement:
|
||||
// Check modifiers
|
||||
if (nodes === (<ClassDeclaration | FunctionLikeDeclaration | VariableStatement>parent).modifiers) {
|
||||
return checkModifiers(<NodeArray<Modifier>>nodes, parent.kind === SyntaxKind.VariableStatement);
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
// Check modifiers of property declaration
|
||||
if (nodes === (<PropertyDeclaration>parent).modifiers) {
|
||||
for (const modifier of <NodeArray<Modifier>>nodes) {
|
||||
if (modifier.kind !== SyntaxKind.StaticKeyword) {
|
||||
diagnostics.push(createDiagnosticForNode(modifier, Diagnostics._0_can_only_be_used_in_a_ts_file, tokenToString(modifier.kind)));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.Parameter:
|
||||
// Check modifiers of parameter declaration
|
||||
if (nodes === (<ParameterDeclaration>parent).modifiers) {
|
||||
diagnostics.push(createDiagnosticForNodeArray(nodes, Diagnostics.parameter_modifiers_can_only_be_used_in_a_ts_file));
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.CallExpression:
|
||||
case SyntaxKind.NewExpression:
|
||||
const expression = <CallExpression>node;
|
||||
if (expression.typeArguments && expression.typeArguments.length > 0) {
|
||||
const start = expression.typeArguments.pos;
|
||||
diagnostics.push(createFileDiagnostic(sourceFile, start, expression.typeArguments.end - start,
|
||||
Diagnostics.type_arguments_can_only_be_used_in_a_ts_file));
|
||||
return true;
|
||||
case SyntaxKind.ExpressionWithTypeArguments:
|
||||
// Check type arguments
|
||||
if (nodes === (<CallExpression | NewExpression | ExpressionWithTypeArguments>parent).typeArguments) {
|
||||
diagnostics.push(createDiagnosticForNodeArray(nodes, Diagnostics.type_arguments_can_only_be_used_in_a_ts_file));
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.Parameter:
|
||||
const parameter = <ParameterDeclaration>node;
|
||||
if (parameter.modifiers) {
|
||||
const start = parameter.modifiers.pos;
|
||||
diagnostics.push(createFileDiagnostic(sourceFile, start, parameter.modifiers.end - start,
|
||||
Diagnostics.parameter_modifiers_can_only_be_used_in_a_ts_file));
|
||||
return true;
|
||||
}
|
||||
if (parameter.questionToken) {
|
||||
diagnostics.push(createDiagnosticForNode(parameter.questionToken, Diagnostics._0_can_only_be_used_in_a_ts_file, "?"));
|
||||
return true;
|
||||
}
|
||||
if (parameter.type) {
|
||||
diagnostics.push(createDiagnosticForNode(parameter.type, Diagnostics.types_can_only_be_used_in_a_ts_file));
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
const propertyDeclaration = <PropertyDeclaration>node;
|
||||
if (propertyDeclaration.modifiers) {
|
||||
for (const modifier of propertyDeclaration.modifiers) {
|
||||
if (modifier.kind !== SyntaxKind.StaticKeyword) {
|
||||
diagnostics.push(createDiagnosticForNode(modifier, Diagnostics._0_can_only_be_used_in_a_ts_file, tokenToString(modifier.kind)));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
for (const node of nodes) {
|
||||
walk(node);
|
||||
}
|
||||
}
|
||||
|
||||
function checkModifiers(modifiers: NodeArray<Modifier>, isConstValid: boolean) {
|
||||
for (const modifier of modifiers) {
|
||||
switch (modifier.kind) {
|
||||
case SyntaxKind.ConstKeyword:
|
||||
if (isConstValid) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (checkTypeAnnotation((<PropertyDeclaration>node).type)) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
diagnostics.push(createDiagnosticForNode(node, Diagnostics.enum_declarations_can_only_be_used_in_a_ts_file));
|
||||
return true;
|
||||
case SyntaxKind.TypeAssertionExpression:
|
||||
let typeAssertionExpression = <TypeAssertion>node;
|
||||
diagnostics.push(createDiagnosticForNode(typeAssertionExpression.type, Diagnostics.type_assertion_expressions_can_only_be_used_in_a_ts_file));
|
||||
return true;
|
||||
case SyntaxKind.Decorator:
|
||||
if (!options.experimentalDecorators) {
|
||||
diagnostics.push(createDiagnosticForNode(node, 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));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// Fallthrough to report error
|
||||
case SyntaxKind.PublicKeyword:
|
||||
case SyntaxKind.PrivateKeyword:
|
||||
case SyntaxKind.ProtectedKeyword:
|
||||
case SyntaxKind.ReadonlyKeyword:
|
||||
case SyntaxKind.DeclareKeyword:
|
||||
case SyntaxKind.AbstractKeyword:
|
||||
diagnostics.push(createDiagnosticForNode(modifier, Diagnostics._0_can_only_be_used_in_a_ts_file, tokenToString(modifier.kind)));
|
||||
break;
|
||||
|
||||
return forEachChild(node, walk);
|
||||
}
|
||||
|
||||
function checkTypeParameters(typeParameters: NodeArray<TypeParameterDeclaration>): boolean {
|
||||
if (typeParameters) {
|
||||
const start = typeParameters.pos;
|
||||
diagnostics.push(createFileDiagnostic(sourceFile, start, typeParameters.end - start, Diagnostics.type_parameter_declarations_can_only_be_used_in_a_ts_file));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function checkTypeAnnotation(type: TypeNode): boolean {
|
||||
if (type) {
|
||||
diagnostics.push(createDiagnosticForNode(type, Diagnostics.types_can_only_be_used_in_a_ts_file));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function checkModifiers(modifiers: NodeArray<Modifier>): boolean {
|
||||
if (modifiers) {
|
||||
for (const modifier of modifiers) {
|
||||
switch (modifier.kind) {
|
||||
case SyntaxKind.PublicKeyword:
|
||||
case SyntaxKind.PrivateKeyword:
|
||||
case SyntaxKind.ProtectedKeyword:
|
||||
case SyntaxKind.ReadonlyKeyword:
|
||||
case SyntaxKind.DeclareKeyword:
|
||||
diagnostics.push(createDiagnosticForNode(modifier, Diagnostics._0_can_only_be_used_in_a_ts_file, tokenToString(modifier.kind)));
|
||||
return true;
|
||||
|
||||
// These are all legal modifiers.
|
||||
case SyntaxKind.StaticKeyword:
|
||||
case SyntaxKind.ExportKeyword:
|
||||
case SyntaxKind.ConstKeyword:
|
||||
case SyntaxKind.DefaultKeyword:
|
||||
case SyntaxKind.AbstractKeyword:
|
||||
}
|
||||
// These are all legal modifiers.
|
||||
case SyntaxKind.StaticKeyword:
|
||||
case SyntaxKind.ExportKeyword:
|
||||
case SyntaxKind.DefaultKeyword:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
function createDiagnosticForNodeArray(nodes: NodeArray<Node>, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number): Diagnostic {
|
||||
const start = nodes.pos;
|
||||
return createFileDiagnostic(sourceFile, start, nodes.end - start, message, arg0, arg1, arg2);
|
||||
}
|
||||
|
||||
// Since these are syntactic diagnostics, parent might not have been set
|
||||
// this means the sourceFile cannot be infered from the node
|
||||
function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number): Diagnostic {
|
||||
return createDiagnosticForNodeInSourceFile(sourceFile, node, message, arg0, arg1, arg2);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1140,9 +1140,14 @@ namespace ts {
|
||||
if (options.importHelpers
|
||||
&& (options.isolatedModules || isExternalModuleFile)
|
||||
&& !file.isDeclarationFile) {
|
||||
const externalHelpersModuleReference = <StringLiteral>createNode(SyntaxKind.StringLiteral);
|
||||
// synthesize 'import "tslib"' declaration
|
||||
const externalHelpersModuleReference = <StringLiteral>createSynthesizedNode(SyntaxKind.StringLiteral);
|
||||
externalHelpersModuleReference.text = externalHelpersModuleNameText;
|
||||
externalHelpersModuleReference.parent = file;
|
||||
const importDecl = createSynthesizedNode(SyntaxKind.ImportDeclaration);
|
||||
|
||||
importDecl.parent = file;
|
||||
externalHelpersModuleReference.parent = importDecl;
|
||||
|
||||
imports = [externalHelpersModuleReference];
|
||||
}
|
||||
|
||||
@@ -1395,14 +1400,17 @@ namespace ts {
|
||||
// If we already resolved to this file, it must have been a secondary reference. Check file contents
|
||||
// for sameness and possibly issue an error
|
||||
if (previousResolution) {
|
||||
const otherFileText = host.readFile(resolvedTypeReferenceDirective.resolvedFileName);
|
||||
if (otherFileText !== getSourceFile(previousResolution.resolvedFileName).text) {
|
||||
fileProcessingDiagnostics.add(createDiagnostic(refFile, refPos, refEnd,
|
||||
Diagnostics.Conflicting_definitions_for_0_found_at_1_and_2_Consider_installing_a_specific_version_of_this_library_to_resolve_the_conflict,
|
||||
typeReferenceDirective,
|
||||
resolvedTypeReferenceDirective.resolvedFileName,
|
||||
previousResolution.resolvedFileName
|
||||
));
|
||||
// Don't bother reading the file again if it's the same file.
|
||||
if (resolvedTypeReferenceDirective.resolvedFileName !== previousResolution.resolvedFileName) {
|
||||
const otherFileText = host.readFile(resolvedTypeReferenceDirective.resolvedFileName);
|
||||
if (otherFileText !== getSourceFile(previousResolution.resolvedFileName).text) {
|
||||
fileProcessingDiagnostics.add(createDiagnostic(refFile, refPos, refEnd,
|
||||
Diagnostics.Conflicting_definitions_for_0_found_at_1_and_2_Consider_installing_a_specific_version_of_this_library_to_resolve_the_conflict,
|
||||
typeReferenceDirective,
|
||||
resolvedTypeReferenceDirective.resolvedFileName,
|
||||
previousResolution.resolvedFileName
|
||||
));
|
||||
}
|
||||
}
|
||||
// don't overwrite previous resolution result
|
||||
saveResolution = false;
|
||||
@@ -1439,7 +1447,9 @@ namespace ts {
|
||||
collectExternalModuleReferences(file);
|
||||
if (file.imports.length || file.moduleAugmentations.length) {
|
||||
file.resolvedModules = createMap<ResolvedModuleFull>();
|
||||
const moduleNames = map(concatenate(file.imports, file.moduleAugmentations), getTextOfLiteral);
|
||||
// Because global augmentation doesn't have string literal name, we can check for global augmentation as such.
|
||||
const nonGlobalAugmentation = filter(file.moduleAugmentations, (moduleAugmentation) => moduleAugmentation.kind === SyntaxKind.StringLiteral);
|
||||
const moduleNames = map(concatenate(file.imports, nonGlobalAugmentation), getTextOfLiteral);
|
||||
const resolutions = resolveModuleNamesReusingOldState(moduleNames, getNormalizedAbsolutePath(file.fileName, currentDirectory), file);
|
||||
Debug.assert(resolutions.length === moduleNames.length);
|
||||
for (let i = 0; i < moduleNames.length; i++) {
|
||||
@@ -1670,7 +1680,15 @@ namespace ts {
|
||||
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators"));
|
||||
}
|
||||
|
||||
if (options.reactNamespace && !isIdentifierText(options.reactNamespace, languageVersion)) {
|
||||
if (options.jsxFactory) {
|
||||
if (options.reactNamespace) {
|
||||
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "reactNamespace", "jsxFactory"));
|
||||
}
|
||||
if (!parseIsolatedEntityName(options.jsxFactory, languageVersion)) {
|
||||
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Invalid_value_for_jsxFactory_0_is_not_a_valid_identifier_or_qualified_name, options.jsxFactory));
|
||||
}
|
||||
}
|
||||
else if (options.reactNamespace && !isIdentifierText(options.reactNamespace, languageVersion)) {
|
||||
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Invalid_value_for_reactNamespace_0_is_not_a_valid_identifier, options.reactNamespace));
|
||||
}
|
||||
|
||||
@@ -1690,18 +1708,13 @@ namespace ts {
|
||||
const emitFilePath = toPath(emitFileName, currentDirectory, getCanonicalFileName);
|
||||
// Report error if the output overwrites input file
|
||||
if (filesByName.contains(emitFilePath)) {
|
||||
if (options.noEmitOverwritenFiles && !options.out && !options.outDir && !options.outFile) {
|
||||
blockEmittingOfFile(emitFileName);
|
||||
}
|
||||
else {
|
||||
let chain: DiagnosticMessageChain;
|
||||
if (!options.configFilePath) {
|
||||
// The program is from either an inferred project or an external project
|
||||
chain = chainDiagnosticMessages(/*details*/ undefined, Diagnostics.Adding_a_tsconfig_json_file_will_help_organize_projects_that_contain_both_TypeScript_and_JavaScript_files_Learn_more_at_https_Colon_Slash_Slashaka_ms_Slashtsconfig);
|
||||
}
|
||||
chain = chainDiagnosticMessages(chain, Diagnostics.Cannot_write_file_0_because_it_would_overwrite_input_file, emitFileName);
|
||||
blockEmittingOfFile(emitFileName, createCompilerDiagnosticFromMessageChain(chain));
|
||||
let chain: DiagnosticMessageChain;
|
||||
if (!options.configFilePath) {
|
||||
// The program is from either an inferred project or an external project
|
||||
chain = chainDiagnosticMessages(/*details*/ undefined, Diagnostics.Adding_a_tsconfig_json_file_will_help_organize_projects_that_contain_both_TypeScript_and_JavaScript_files_Learn_more_at_https_Colon_Slash_Slashaka_ms_Slashtsconfig);
|
||||
}
|
||||
chain = chainDiagnosticMessages(chain, Diagnostics.Cannot_write_file_0_because_it_would_overwrite_input_file, emitFileName);
|
||||
blockEmittingOfFile(emitFileName, createCompilerDiagnosticFromMessageChain(chain));
|
||||
}
|
||||
|
||||
// Report error if multiple files write into same file
|
||||
@@ -1716,11 +1729,9 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function blockEmittingOfFile(emitFileName: string, diag?: Diagnostic) {
|
||||
function blockEmittingOfFile(emitFileName: string, diag: Diagnostic) {
|
||||
hasEmitBlockingDiagnostics.set(toPath(emitFileName, currentDirectory, getCanonicalFileName), true);
|
||||
if (diag) {
|
||||
programDiagnostics.add(diag);
|
||||
}
|
||||
programDiagnostics.add(diag);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+16
-12
@@ -1,6 +1,7 @@
|
||||
/// <reference path="visitor.ts" />
|
||||
/// <reference path="transformers/ts.ts" />
|
||||
/// <reference path="transformers/jsx.ts" />
|
||||
/// <reference path="transformers/esnext.ts" />
|
||||
/// <reference path="transformers/es2017.ts" />
|
||||
/// <reference path="transformers/es2016.ts" />
|
||||
/// <reference path="transformers/es2015.ts" />
|
||||
@@ -38,6 +39,10 @@ namespace ts {
|
||||
transformers.push(transformJsx);
|
||||
}
|
||||
|
||||
if (languageVersion < ScriptTarget.ESNext) {
|
||||
transformers.push(transformESNext);
|
||||
}
|
||||
|
||||
if (languageVersion < ScriptTarget.ES2017) {
|
||||
transformers.push(transformES2017);
|
||||
}
|
||||
@@ -73,7 +78,7 @@ namespace ts {
|
||||
export function transformFiles(resolver: EmitResolver, host: EmitHost, sourceFiles: SourceFile[], transformers: Transformer[]): TransformationResult {
|
||||
const enabledSyntaxKindFeatures = new Array<SyntaxKindFeatureFlags>(SyntaxKind.Count);
|
||||
|
||||
let scopeModificationDisabled = false;
|
||||
let lexicalEnvironmentDisabled = false;
|
||||
|
||||
let lexicalEnvironmentVariableDeclarations: VariableDeclaration[];
|
||||
let lexicalEnvironmentFunctionDeclarations: FunctionDeclaration[];
|
||||
@@ -113,7 +118,7 @@ namespace ts {
|
||||
const transformed = map(sourceFiles, transformSourceFile);
|
||||
|
||||
// Disable modification of the lexical environment.
|
||||
scopeModificationDisabled = true;
|
||||
lexicalEnvironmentDisabled = true;
|
||||
|
||||
return {
|
||||
transformed,
|
||||
@@ -208,7 +213,7 @@ namespace ts {
|
||||
* Records a hoisted variable declaration for the provided name within a lexical environment.
|
||||
*/
|
||||
function hoistVariableDeclaration(name: Identifier): void {
|
||||
Debug.assert(!scopeModificationDisabled, "Cannot modify the lexical environment during the print phase.");
|
||||
Debug.assert(!lexicalEnvironmentDisabled, "Cannot modify the lexical environment during the print phase.");
|
||||
const decl = createVariableDeclaration(name);
|
||||
if (!lexicalEnvironmentVariableDeclarations) {
|
||||
lexicalEnvironmentVariableDeclarations = [decl];
|
||||
@@ -222,7 +227,7 @@ namespace ts {
|
||||
* Records a hoisted function declaration within a lexical environment.
|
||||
*/
|
||||
function hoistFunctionDeclaration(func: FunctionDeclaration): void {
|
||||
Debug.assert(!scopeModificationDisabled, "Cannot modify the lexical environment during the print phase.");
|
||||
Debug.assert(!lexicalEnvironmentDisabled, "Cannot modify the lexical environment during the print phase.");
|
||||
if (!lexicalEnvironmentFunctionDeclarations) {
|
||||
lexicalEnvironmentFunctionDeclarations = [func];
|
||||
}
|
||||
@@ -236,7 +241,7 @@ namespace ts {
|
||||
* are pushed onto a stack, and the related storage variables are reset.
|
||||
*/
|
||||
function startLexicalEnvironment(): void {
|
||||
Debug.assert(!scopeModificationDisabled, "Cannot start a lexical environment during the print phase.");
|
||||
Debug.assert(!lexicalEnvironmentDisabled, "Cannot start a lexical environment during the print phase.");
|
||||
Debug.assert(!lexicalEnvironmentSuspended, "Lexical environment is suspended.");
|
||||
|
||||
// Save the current lexical environment. Rather than resizing the array we adjust the
|
||||
@@ -252,15 +257,15 @@ namespace ts {
|
||||
|
||||
/** Suspends the current lexical environment, usually after visiting a parameter list. */
|
||||
function suspendLexicalEnvironment(): void {
|
||||
Debug.assert(!scopeModificationDisabled, "Cannot suspend a lexical environment during the print phase.");
|
||||
Debug.assert(!lexicalEnvironmentDisabled, "Cannot suspend a lexical environment during the print phase.");
|
||||
Debug.assert(!lexicalEnvironmentSuspended, "Lexical environment is already suspended.");
|
||||
lexicalEnvironmentSuspended = true;
|
||||
}
|
||||
|
||||
/** Resumes a suspended lexical environment, usually before visiting a function body. */
|
||||
function resumeLexicalEnvironment(): void {
|
||||
Debug.assert(!scopeModificationDisabled, "Cannot resume a lexical environment during the print phase.");
|
||||
Debug.assert(lexicalEnvironmentSuspended, "Lexical environment is not suspended suspended.");
|
||||
Debug.assert(!lexicalEnvironmentDisabled, "Cannot resume a lexical environment during the print phase.");
|
||||
Debug.assert(lexicalEnvironmentSuspended, "Lexical environment is not suspended.");
|
||||
lexicalEnvironmentSuspended = false;
|
||||
}
|
||||
|
||||
@@ -269,7 +274,7 @@ namespace ts {
|
||||
* any hoisted declarations added in this environment are returned.
|
||||
*/
|
||||
function endLexicalEnvironment(): Statement[] {
|
||||
Debug.assert(!scopeModificationDisabled, "Cannot end a lexical environment during the print phase.");
|
||||
Debug.assert(!lexicalEnvironmentDisabled, "Cannot end a lexical environment during the print phase.");
|
||||
Debug.assert(!lexicalEnvironmentSuspended, "Lexical environment is suspended.");
|
||||
|
||||
let statements: Statement[];
|
||||
@@ -301,18 +306,17 @@ namespace ts {
|
||||
lexicalEnvironmentVariableDeclarationsStack = [];
|
||||
lexicalEnvironmentFunctionDeclarationsStack = [];
|
||||
}
|
||||
|
||||
return statements;
|
||||
}
|
||||
|
||||
function requestEmitHelper(helper: EmitHelper): void {
|
||||
Debug.assert(!scopeModificationDisabled, "Cannot modify the lexical environment during the print phase.");
|
||||
Debug.assert(!lexicalEnvironmentDisabled, "Cannot modify the lexical environment during the print phase.");
|
||||
Debug.assert(!helper.scoped, "Cannot request a scoped emit helper.");
|
||||
emitHelpers = append(emitHelpers, helper);
|
||||
}
|
||||
|
||||
function readEmitHelpers(): EmitHelper[] | undefined {
|
||||
Debug.assert(!scopeModificationDisabled, "Cannot modify the lexical environment during the print phase.");
|
||||
Debug.assert(!lexicalEnvironmentDisabled, "Cannot modify the lexical environment during the print phase.");
|
||||
const helpers = emitHelpers;
|
||||
emitHelpers = undefined;
|
||||
return helpers;
|
||||
|
||||
@@ -3,51 +3,41 @@
|
||||
|
||||
/*@internal*/
|
||||
namespace ts {
|
||||
type EffectiveBindingElement
|
||||
= VariableDeclaration
|
||||
| ParameterDeclaration
|
||||
| BindingElement
|
||||
| ObjectLiteralElementLike
|
||||
| Expression
|
||||
;
|
||||
interface FlattenContext {
|
||||
context: TransformationContext;
|
||||
level: FlattenLevel;
|
||||
hoistTempVariables: boolean;
|
||||
emitExpression: (value: Expression) => void;
|
||||
emitBindingOrAssignment: (target: BindingOrAssignmentElementTarget, value: Expression, location: TextRange, original: Node) => void;
|
||||
createArrayBindingOrAssignmentPattern: (elements: BindingOrAssignmentElement[]) => ArrayBindingOrAssignmentPattern;
|
||||
createObjectBindingOrAssignmentPattern: (elements: BindingOrAssignmentElement[]) => ObjectBindingOrAssignmentPattern;
|
||||
createArrayBindingOrAssignmentElement: (node: Identifier) => BindingOrAssignmentElement;
|
||||
visitor?: (node: Node) => VisitResult<Node>;
|
||||
}
|
||||
|
||||
type EffectiveObjectBindingPattern
|
||||
= ObjectBindingPattern
|
||||
| ObjectLiteralExpression
|
||||
;
|
||||
|
||||
type EffectiveArrayBindingPattern
|
||||
= ArrayBindingPattern
|
||||
| ArrayLiteralExpression
|
||||
;
|
||||
|
||||
type EffectiveBindingPattern
|
||||
= EffectiveObjectBindingPattern
|
||||
| EffectiveArrayBindingPattern
|
||||
;
|
||||
|
||||
type EffectiveBindingTarget
|
||||
= EffectiveBindingPattern
|
||||
| Expression
|
||||
;
|
||||
export const enum FlattenLevel {
|
||||
All,
|
||||
ObjectRest,
|
||||
}
|
||||
|
||||
/**
|
||||
* Flattens a DestructuringAssignment or a VariableDeclaration to an expression.
|
||||
*
|
||||
* @param node The node to flatten.
|
||||
* @param needsValue Indicates whether the value from the right-hand-side of the
|
||||
* destructuring assignment is needed as part of a larger expression.
|
||||
* @param createAssignmentCallback A callback used to create an assignment expression.
|
||||
* @param recordTempVariable A callback used to record new temporary variables.
|
||||
* @param visitor An optional visitor used to visit default value initializers of binding patterns.
|
||||
* @param visitor An optional visitor used to visit initializers.
|
||||
* @param context The transformation context.
|
||||
* @param level Indicates the extent to which flattening should occur.
|
||||
* @param needsValue An optional value indicating whether the value from the right-hand-side of
|
||||
* the destructuring assignment is needed as part of a larger expression.
|
||||
* @param createAssignmentCallback An optional callback used to create the assignment expression.
|
||||
*/
|
||||
export function flattenDestructuringToExpression(
|
||||
context: TransformationContext,
|
||||
export function flattenDestructuringAssignment(
|
||||
node: VariableDeclaration | DestructuringAssignment,
|
||||
needsValue: boolean,
|
||||
createAssignmentCallback: (target: Expression, value: Expression, location?: TextRange) => Expression,
|
||||
visitor?: (node: Node) => VisitResult<Node>): Expression {
|
||||
|
||||
visitor: ((node: Node) => VisitResult<Node>) | undefined,
|
||||
context: TransformationContext,
|
||||
level: FlattenLevel,
|
||||
needsValue?: boolean,
|
||||
createAssignmentCallback?: (name: Identifier, value: Expression, location?: TextRange) => Expression): Expression {
|
||||
let location: TextRange = node;
|
||||
let value: Expression;
|
||||
if (isDestructuringAssignment(node)) {
|
||||
@@ -63,7 +53,18 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
const expressions: Expression[] = [];
|
||||
let expressions: Expression[];
|
||||
const flattenContext: FlattenContext = {
|
||||
context,
|
||||
level,
|
||||
hoistTempVariables: true,
|
||||
emitExpression,
|
||||
emitBindingOrAssignment,
|
||||
createArrayBindingOrAssignmentPattern: makeArrayAssignmentPattern,
|
||||
createObjectBindingOrAssignmentPattern: makeObjectAssignmentPattern,
|
||||
createArrayBindingOrAssignmentElement: makeAssignmentElement,
|
||||
visitor
|
||||
};
|
||||
|
||||
if (value) {
|
||||
value = visitNode(value, visitor, isExpression);
|
||||
@@ -74,7 +75,7 @@ namespace ts {
|
||||
//
|
||||
// The source map location for the assignment should point to the entire binary
|
||||
// expression.
|
||||
value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true, emitTempVariableAssignment, location);
|
||||
value = ensureIdentifier(flattenContext, value, /*reuseIdentifierExpressions*/ true, location);
|
||||
}
|
||||
else if (nodeIsSynthesized(node)) {
|
||||
// Generally, the source map location for a destructuring assignment is the root
|
||||
@@ -87,520 +88,328 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
flattenEffectiveBindingElement(
|
||||
context,
|
||||
node,
|
||||
value,
|
||||
isDestructuringAssignment(node),
|
||||
emitAssignment,
|
||||
emitTempVariableAssignment,
|
||||
emitExpression,
|
||||
visitor,
|
||||
location);
|
||||
flattenBindingOrAssignmentElement(flattenContext, node, value, location, /*skipInitializer*/ isDestructuringAssignment(node));
|
||||
|
||||
if (value && needsValue) {
|
||||
if (!some(expressions)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
expressions.push(value);
|
||||
}
|
||||
|
||||
return aggregateTransformFlags(inlineExpressions(expressions));
|
||||
|
||||
function emitAssignment(target: Expression, value: Expression, location: TextRange, original: Node) {
|
||||
const expression = createAssignmentCallback(target, value, location);
|
||||
expression.original = original;
|
||||
emitExpression(expression);
|
||||
}
|
||||
|
||||
function emitTempVariableAssignment(value: Expression, location: TextRange) {
|
||||
const name = createTempVariable(context.hoistVariableDeclaration);
|
||||
emitExpression(createAssignment(name, value, location));
|
||||
return name;
|
||||
}
|
||||
return aggregateTransformFlags(inlineExpressions(expressions)) || createOmittedExpression();
|
||||
|
||||
function emitExpression(expression: Expression) {
|
||||
// NOTE: this completely disables source maps, but aligns with the behavior of
|
||||
// `emitAssignment` in the old emitter.
|
||||
setEmitFlags(expression, EmitFlags.NoNestedSourceMaps);
|
||||
aggregateTransformFlags(expression);
|
||||
expressions.push(expression);
|
||||
expressions = append(expressions, expression);
|
||||
}
|
||||
|
||||
function emitBindingOrAssignment(target: BindingOrAssignmentElementTarget, value: Expression, location: TextRange, original: Node) {
|
||||
Debug.assertNode(target, createAssignmentCallback ? isIdentifier : isExpression);
|
||||
const expression = createAssignmentCallback
|
||||
? createAssignmentCallback(<Identifier>target, value, location)
|
||||
: createAssignment(visitNode(<Expression>target, visitor, isExpression), value, location);
|
||||
expression.original = original;
|
||||
emitExpression(expression);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flattens binding patterns in a VariableDeclaration or a ParameterDeclaration to a VariableDeclaration list.
|
||||
* Flattens a VariableDeclaration or ParameterDeclaration to one or more variable declarations.
|
||||
*
|
||||
* @param node The node to flatten.
|
||||
* @param boundValue An optional rhs value for the binding pattern. This value is *not* visited during flattening.
|
||||
* @param visitor An optional visitor to use to visit expressions.
|
||||
* @param recordTempVariable An optional callback used to hoist temporary variables rather than
|
||||
* declaring them inline.
|
||||
* @param visitor An optional visitor used to visit initializers.
|
||||
* @param context The transformation context.
|
||||
* @param boundValue The value bound to the declaration.
|
||||
* @param skipInitializer A value indicating whether to ignore the initializer of `node`.
|
||||
* @param hoistTempVariables Indicates whether temporary variables should not be recorded in-line.
|
||||
* @param level Indicates the extent to which flattening should occur.
|
||||
*/
|
||||
export function flattenDestructuring(
|
||||
context: TransformationContext,
|
||||
export function flattenDestructuringBinding(
|
||||
node: VariableDeclaration | ParameterDeclaration,
|
||||
boundValue: Expression | undefined,
|
||||
recordTempVariablesInLine: boolean,
|
||||
visitor?: (node: Node) => VisitResult<Node>) {
|
||||
|
||||
visitor: (node: Node) => VisitResult<Node>,
|
||||
context: TransformationContext,
|
||||
level: FlattenLevel,
|
||||
rval?: Expression,
|
||||
hoistTempVariables?: boolean,
|
||||
skipInitializer?: boolean): VariableDeclaration[] {
|
||||
let pendingExpressions: Expression[];
|
||||
const pendingDeclarations: { pendingExpressions?: Expression[], name: Identifier, value: Expression, location?: TextRange, original?: Node }[] = [];
|
||||
const pendingDeclarations: { pendingExpressions?: Expression[], name: BindingName, value: Expression, location?: TextRange, original?: Node; }[] = [];
|
||||
const declarations: VariableDeclaration[] = [];
|
||||
|
||||
flattenEffectiveBindingElement(
|
||||
const flattenContext: FlattenContext = {
|
||||
context,
|
||||
node,
|
||||
boundValue,
|
||||
/*skipInitializer*/ false,
|
||||
emitAssignment,
|
||||
emitTempVariableAssignment,
|
||||
level,
|
||||
hoistTempVariables,
|
||||
emitExpression,
|
||||
visitor,
|
||||
/*location*/ node);
|
||||
|
||||
emitBindingOrAssignment,
|
||||
createArrayBindingOrAssignmentPattern: makeArrayBindingPattern,
|
||||
createObjectBindingOrAssignmentPattern: makeObjectBindingPattern,
|
||||
createArrayBindingOrAssignmentElement: makeBindingElement,
|
||||
visitor
|
||||
};
|
||||
flattenBindingOrAssignmentElement(flattenContext, node, rval, node, skipInitializer);
|
||||
if (pendingExpressions) {
|
||||
const name = createTempVariable(/*recordTempVariable*/ undefined);
|
||||
if (recordTempVariablesInLine) {
|
||||
pendingDeclarations.push({ name, value: inlineExpressions(pendingExpressions) });
|
||||
const temp = createTempVariable(/*recordTempVariable*/ undefined);
|
||||
if (hoistTempVariables) {
|
||||
const value = inlineExpressions(pendingExpressions);
|
||||
pendingExpressions = undefined;
|
||||
emitBindingOrAssignment(temp, value, /*location*/ undefined, /*original*/ undefined);
|
||||
}
|
||||
else {
|
||||
context.hoistVariableDeclaration(name);
|
||||
context.hoistVariableDeclaration(temp);
|
||||
const pendingDeclaration = lastOrUndefined(pendingDeclarations);
|
||||
pendingDeclaration.pendingExpressions = append(
|
||||
pendingDeclaration.pendingExpressions,
|
||||
createAssignment(name, pendingDeclaration.value)
|
||||
createAssignment(temp, pendingDeclaration.value)
|
||||
);
|
||||
addRange(pendingDeclaration.pendingExpressions, pendingExpressions);
|
||||
pendingDeclaration.value = name;
|
||||
pendingDeclaration.value = temp;
|
||||
}
|
||||
}
|
||||
|
||||
for (const { pendingExpressions, name, value, location, original} of pendingDeclarations) {
|
||||
const declaration = createVariableDeclaration(
|
||||
for (const { pendingExpressions, name, value, location, original } of pendingDeclarations) {
|
||||
const variable = createVariableDeclaration(
|
||||
name,
|
||||
/*type*/ undefined,
|
||||
// pendingExpressions
|
||||
// ? inlineExpressions(append(pendingExpressions, value))
|
||||
// : value,
|
||||
inlineExpressions(append(pendingExpressions, value)),
|
||||
location
|
||||
);
|
||||
|
||||
declaration.original = original;
|
||||
|
||||
// NOTE: this completely disables source maps, but aligns with the behavior of
|
||||
// `emitAssignment` in the old emitter.
|
||||
declarations.push(aggregateTransformFlags(setEmitFlags(declaration, EmitFlags.NoNestedSourceMaps)));
|
||||
pendingExpressions ? inlineExpressions(append(pendingExpressions, value)) : value,
|
||||
location);
|
||||
variable.original = original;
|
||||
if (isIdentifier(name)) {
|
||||
setEmitFlags(variable, EmitFlags.NoNestedSourceMaps);
|
||||
}
|
||||
aggregateTransformFlags(variable);
|
||||
declarations.push(variable);
|
||||
}
|
||||
|
||||
return declarations;
|
||||
|
||||
function emitAssignment(name: Expression, value: Expression, location: TextRange, original: Node) {
|
||||
if (!isIdentifier(name)) {
|
||||
Debug.failBadSyntaxKind(name, "Identifier expected.");
|
||||
return;
|
||||
}
|
||||
|
||||
pendingDeclarations.push({ pendingExpressions, name, value, location, original });
|
||||
pendingExpressions = undefined;
|
||||
function emitExpression(value: Expression) {
|
||||
pendingExpressions = append(pendingExpressions, value);
|
||||
}
|
||||
|
||||
function emitTempVariableAssignment(value: Expression, location: TextRange) {
|
||||
const name = createTempVariable(/*recordTempVariable*/ undefined);
|
||||
if (recordTempVariablesInLine) {
|
||||
emitAssignment(name, value, location, /*original*/ undefined);
|
||||
function emitBindingOrAssignment(target: BindingOrAssignmentElementTarget, value: Expression, location: TextRange, original: Node) {
|
||||
Debug.assertNode(target, isBindingName);
|
||||
if (pendingExpressions) {
|
||||
value = inlineExpressions(append(pendingExpressions, value));
|
||||
pendingExpressions = undefined;
|
||||
}
|
||||
else {
|
||||
context.hoistVariableDeclaration(name);
|
||||
emitExpression(createAssignment(name, value, location));
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
function emitExpression(expression: Expression) {
|
||||
pendingExpressions = append(pendingExpressions, expression);
|
||||
pendingDeclarations.push({ pendingExpressions, name: <BindingName>target, value, location, original });
|
||||
}
|
||||
}
|
||||
|
||||
function flattenEffectiveBindingElement(
|
||||
context: TransformationContext,
|
||||
bindingElement: EffectiveBindingElement,
|
||||
boundValue: Expression | undefined,
|
||||
skipInitializer: boolean,
|
||||
emitAssignment: (target: Expression, value: Expression, location: TextRange, original: Node) => void,
|
||||
emitTempVariableAssignment: (value: Expression, location: TextRange) => Identifier,
|
||||
emitExpression: (value: Expression) => void,
|
||||
visitor: ((node: Node) => VisitResult<Node>) | undefined,
|
||||
location: TextRange) {
|
||||
|
||||
/**
|
||||
* Flattens a BindingOrAssignmentElement into zero or more bindings or assignments.
|
||||
*
|
||||
* @param flattenContext Options used to control flattening.
|
||||
* @param element The element to flatten.
|
||||
* @param value The current RHS value to assign to the element.
|
||||
* @param location The location to use for source maps and comments.
|
||||
* @param skipInitializer An optional value indicating whether to include the initializer
|
||||
* for the element.
|
||||
*/
|
||||
function flattenBindingOrAssignmentElement(
|
||||
flattenContext: FlattenContext,
|
||||
element: BindingOrAssignmentElement,
|
||||
value: Expression | undefined,
|
||||
location: TextRange,
|
||||
skipInitializer?: boolean) {
|
||||
if (!skipInitializer) {
|
||||
const initializer = visitNode(getInitializerOfEffectiveBindingElement(bindingElement), visitor, isExpression);
|
||||
const initializer = visitNode(getInitializerOfBindingOrAssignmentElement(element), flattenContext.visitor, isExpression);
|
||||
if (initializer) {
|
||||
// Combine value and initializer
|
||||
boundValue = boundValue ? createDefaultValueCheck(boundValue, initializer, location, emitTempVariableAssignment) : initializer;
|
||||
value = value ? createDefaultValueCheck(flattenContext, value, initializer, location) : initializer;
|
||||
}
|
||||
else if (!boundValue) {
|
||||
else if (!value) {
|
||||
// Use 'void 0' in absence of value and initializer
|
||||
boundValue = createVoidZero();
|
||||
value = createVoidZero();
|
||||
}
|
||||
}
|
||||
|
||||
const bindingTarget = getTargetOfEffectiveBindingElement(bindingElement);
|
||||
if (isEffectiveBindingPattern(bindingTarget)) {
|
||||
const elements = getElementsOfEffectiveBindingPattern(bindingTarget);
|
||||
const numElements = elements.length;
|
||||
if (isEffectiveArrayBindingPattern(bindingTarget) && !isArrayLiteralExpression(boundValue)) {
|
||||
// Read the elements of the iterable into an array
|
||||
boundValue = emitTempVariableAssignment(
|
||||
createReadHelper(
|
||||
context,
|
||||
boundValue,
|
||||
numElements > 0 && isEffectiveBindingElementWithRest(elements[numElements - 1])
|
||||
? undefined
|
||||
: numElements,
|
||||
location
|
||||
),
|
||||
location
|
||||
);
|
||||
}
|
||||
else if (numElements !== 1) {
|
||||
// For anything other than a single-element destructuring we need to generate a temporary
|
||||
// to ensure value is evaluated exactly once. Additionally, if we have zero elements
|
||||
// we need to emit *something* to ensure that in case a 'var' keyword was already emitted,
|
||||
// so in that case, we'll intentionally create that temporary.
|
||||
const reuseIdentifierExpressions = !isDeclarationBindingElement(bindingElement) || numElements !== 0;
|
||||
boundValue = ensureIdentifier(boundValue, reuseIdentifierExpressions, emitTempVariableAssignment, location);
|
||||
}
|
||||
|
||||
if (isEffectiveObjectBindingPattern(bindingTarget)) {
|
||||
for (const element of elements) {
|
||||
// Rewrite element to a declaration with an initializer that fetches property
|
||||
flattenEffectiveBindingElement(
|
||||
context,
|
||||
element,
|
||||
createDestructuringPropertyAccess(
|
||||
boundValue,
|
||||
getEffectivePropertyNameOfEffectiveBindingElement(element),
|
||||
emitTempVariableAssignment),
|
||||
/*skipInitializer*/ false,
|
||||
emitAssignment,
|
||||
emitTempVariableAssignment,
|
||||
emitExpression,
|
||||
visitor,
|
||||
/*location*/ element);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (let i = 0; i < numElements; i++) {
|
||||
const element = elements[i];
|
||||
if (isOmittedExpression(element)) {
|
||||
continue;
|
||||
}
|
||||
else if (!isEffectiveBindingElementWithRest(element)) {
|
||||
flattenEffectiveBindingElement(
|
||||
context,
|
||||
element,
|
||||
createElementAccess(boundValue, i),
|
||||
/*skipInitializer*/ false,
|
||||
emitAssignment,
|
||||
emitTempVariableAssignment,
|
||||
emitExpression,
|
||||
visitor,
|
||||
/*location*/ element);
|
||||
}
|
||||
else if (i === numElements - 1) {
|
||||
flattenEffectiveBindingElement(
|
||||
context,
|
||||
element,
|
||||
createArraySlice(boundValue, i),
|
||||
/*skipInitializer*/ false,
|
||||
emitAssignment,
|
||||
emitTempVariableAssignment,
|
||||
emitExpression,
|
||||
visitor,
|
||||
/*location*/ element);
|
||||
}
|
||||
}
|
||||
}
|
||||
const bindingTarget = getTargetOfBindingOrAssignmentElement(element);
|
||||
if (isObjectBindingOrAssignmentPattern(bindingTarget)) {
|
||||
flattenObjectBindingOrAssignmentPattern(flattenContext, element, bindingTarget, value, location);
|
||||
}
|
||||
else if (isArrayBindingOrAssignmentPattern(bindingTarget)) {
|
||||
flattenArrayBindingOrAssignmentPattern(flattenContext, element, bindingTarget, value, location);
|
||||
}
|
||||
else {
|
||||
emitAssignment(bindingTarget, boundValue, location, /*original*/ bindingElement);
|
||||
flattenContext.emitBindingOrAssignment(bindingTarget, value, location, /*original*/ element);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the BindingElement-like is a declaration
|
||||
* Flattens an ObjectBindingOrAssignmentPattern into zero or more bindings or assignments.
|
||||
*
|
||||
* @param flattenContext Options used to control flattening.
|
||||
* @param parent The parent element of the pattern.
|
||||
* @param pattern The ObjectBindingOrAssignmentPattern to flatten.
|
||||
* @param value The current RHS value to assign to the element.
|
||||
* @param location The location to use for source maps and comments.
|
||||
*/
|
||||
function isDeclarationBindingElement(bindingElement: EffectiveBindingElement): bindingElement is VariableDeclaration | ParameterDeclaration | BindingElement {
|
||||
switch (bindingElement.kind) {
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
case SyntaxKind.Parameter:
|
||||
case SyntaxKind.BindingElement:
|
||||
return true;
|
||||
function flattenObjectBindingOrAssignmentPattern(flattenContext: FlattenContext, parent: BindingOrAssignmentElement, pattern: ObjectBindingOrAssignmentPattern, value: Expression, location: TextRange) {
|
||||
const elements = getElementsOfBindingOrAssignmentPattern(pattern);
|
||||
const numElements = elements.length;
|
||||
if (numElements !== 1) {
|
||||
// For anything other than a single-element destructuring we need to generate a temporary
|
||||
// to ensure value is evaluated exactly once. Additionally, if we have zero elements
|
||||
// we need to emit *something* to ensure that in case a 'var' keyword was already emitted,
|
||||
// so in that case, we'll intentionally create that temporary.
|
||||
const reuseIdentifierExpressions = !isDeclarationBindingElement(parent) || numElements !== 0;
|
||||
value = ensureIdentifier(flattenContext, value, reuseIdentifierExpressions, location);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the initializer of a BindingElement-like element
|
||||
*/
|
||||
function getInitializerOfEffectiveBindingElement(bindingElement: EffectiveBindingElement): Expression | undefined {
|
||||
if (isDeclarationBindingElement(bindingElement)) {
|
||||
// `1` in `let { a = 1 } = ...`
|
||||
// `1` in `let { a: b = 1 } = ...`
|
||||
// `1` in `let { a: {b} = 1 } = ...`
|
||||
// `1` in `let { a: [b] = 1 } = ...`
|
||||
// `1` in `let [a = 1] = ...`
|
||||
// `1` in `let [{a} = 1] = ...`
|
||||
// `1` in `let [[a] = 1] = ...`
|
||||
return bindingElement.initializer;
|
||||
}
|
||||
|
||||
if (isPropertyAssignment(bindingElement)) {
|
||||
// `1` in `({ a: b = 1 } = ...)`
|
||||
// `1` in `({ a: {b} = 1 } = ...)`
|
||||
// `1` in `({ a: [b] = 1 } = ...)`
|
||||
return isAssignmentExpression(bindingElement.initializer, /*excludeCompoundAssignment*/ true)
|
||||
? bindingElement.initializer.right
|
||||
: undefined;
|
||||
}
|
||||
|
||||
if (isShorthandPropertyAssignment(bindingElement)) {
|
||||
// `1` in `({ a = 1 } = ...)`
|
||||
return bindingElement.objectAssignmentInitializer;
|
||||
}
|
||||
|
||||
if (isAssignmentExpression(bindingElement, /*excludeCompoundAssignment*/ true)) {
|
||||
// `1` in `[a = 1] = ...`
|
||||
// `1` in `[{a} = 1] = ...`
|
||||
// `1` in `[[a] = 1] = ...`
|
||||
return bindingElement.right;
|
||||
}
|
||||
|
||||
if (isSpreadElementExpression(bindingElement) || isPartiallyEmittedExpression(bindingElement)) {
|
||||
// Recovery consistent with existing emit.
|
||||
return getInitializerOfEffectiveBindingElement(bindingElement.expression);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of a BindingElement-like element
|
||||
*/
|
||||
function getTargetOfEffectiveBindingElement(bindingElement: EffectiveBindingElement): EffectiveBindingTarget {
|
||||
if (isDeclarationBindingElement(bindingElement)) {
|
||||
// `a` in `let { a } = ...`
|
||||
// `a` in `let { a = 1 } = ...`
|
||||
// `b` in `let { a: b } = ...`
|
||||
// `b` in `let { a: b = 1 } = ...`
|
||||
// `{b}` in `let { a: {b} } = ...`
|
||||
// `{b}` in `let { a: {b} = 1 } = ...`
|
||||
// `[b]` in `let { a: [b] } = ...`
|
||||
// `[b]` in `let { a: [b] = 1 } = ...`
|
||||
// `a` in `let [a] = ...`
|
||||
// `a` in `let [a = 1] = ...`
|
||||
// `a` in `let [...a] = ...`
|
||||
// `{a}` in `let [{a}] = ...`
|
||||
// `{a}` in `let [{a} = 1] = ...`
|
||||
// `[a]` in `let [[a]] = ...`
|
||||
// `[a]` in `let [[a] = 1] = ...`
|
||||
return <ObjectBindingPattern | ArrayBindingPattern | Identifier>bindingElement.name;
|
||||
}
|
||||
|
||||
if (isObjectLiteralElementLike(bindingElement)) {
|
||||
switch (bindingElement.kind) {
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
// `b` in `({ a: b } = ...)`
|
||||
// `b` in `({ a: b = 1 } = ...)`
|
||||
// `{b}` in `({ a: {b} } = ...)`
|
||||
// `{b}` in `({ a: {b} = 1 } = ...)`
|
||||
// `[b]` in `({ a: [b] } = ...)`
|
||||
// `[b]` in `({ a: [b] = 1 } = ...)`
|
||||
// `b.c` in `({ a: b.c } = ...)`
|
||||
// `b.c` in `({ a: b.c = 1 } = ...)`
|
||||
// `b[0]` in `({ a: b[0] } = ...)`
|
||||
// `b[0]` in `({ a: b[0] = 1 } = ...)`
|
||||
return getTargetOfEffectiveBindingElement(bindingElement.initializer);
|
||||
|
||||
case SyntaxKind.ShorthandPropertyAssignment:
|
||||
// `a` in `({ a } = ...)`
|
||||
// `a` in `({ a = 1 } = ...)`
|
||||
return bindingElement.name;
|
||||
let bindingElements: BindingOrAssignmentElement[];
|
||||
let computedTempVariables: Expression[];
|
||||
for (let i = 0; i < numElements; i++) {
|
||||
const element = elements[i];
|
||||
if (!getRestIndicatorOfBindingOrAssignmentElement(element)) {
|
||||
const propertyName = getPropertyNameOfBindingOrAssignmentElement(element);
|
||||
if (flattenContext.level >= FlattenLevel.ObjectRest
|
||||
&& !(element.transformFlags & (TransformFlags.ContainsRest | TransformFlags.ContainsObjectRest))
|
||||
&& !(getTargetOfBindingOrAssignmentElement(element).transformFlags & (TransformFlags.ContainsRest | TransformFlags.ContainsObjectRest))
|
||||
&& !isComputedPropertyName(propertyName)) {
|
||||
bindingElements = append(bindingElements, element);
|
||||
}
|
||||
else {
|
||||
if (bindingElements) {
|
||||
flattenContext.emitBindingOrAssignment(flattenContext.createObjectBindingOrAssignmentPattern(bindingElements), value, location, pattern);
|
||||
bindingElements = undefined;
|
||||
}
|
||||
const rhsValue = createDestructuringPropertyAccess(flattenContext, value, propertyName);
|
||||
if (isComputedPropertyName(propertyName)) {
|
||||
computedTempVariables = append(computedTempVariables, (rhsValue as ElementAccessExpression).argumentExpression);
|
||||
}
|
||||
flattenBindingOrAssignmentElement(flattenContext, element, rhsValue, /*location*/ element);
|
||||
}
|
||||
}
|
||||
|
||||
// no target
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (isAssignmentExpression(bindingElement, /*excludeCompoundAssignment*/ true)) {
|
||||
// `a` in `[a = 1] = ...`
|
||||
// `{a}` in `[{a} = 1] = ...`
|
||||
// `[a]` in `[[a] = 1] = ...`
|
||||
// `a.b` in `[a.b = 1] = ...`
|
||||
// `a[0]` in `[a[0] = 1] = ...`
|
||||
return getTargetOfEffectiveBindingElement(bindingElement.left);
|
||||
}
|
||||
|
||||
if (isSpreadElementExpression(bindingElement) || isPartiallyEmittedExpression(bindingElement)) {
|
||||
// `a` in `[...a] = ...`
|
||||
return getTargetOfEffectiveBindingElement(bindingElement.expression);
|
||||
}
|
||||
|
||||
// `a` in `[a] = ...`
|
||||
// `{a}` in `[{a}] = ...`
|
||||
// `[a]` in `[[a]] = ...`
|
||||
// `a.b` in `[a.b] = ...`
|
||||
// `a[0]` in `[a[0]] = ...`
|
||||
return bindingElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a BindingElement-like element is a rest element.
|
||||
*/
|
||||
function isEffectiveBindingElementWithRest(bindingElement: EffectiveBindingElement) {
|
||||
switch (bindingElement.kind) {
|
||||
case SyntaxKind.Parameter:
|
||||
case SyntaxKind.BindingElement:
|
||||
// `...` in `let [...a] = ...`
|
||||
return (<ParameterDeclaration | BindingElement>bindingElement).dotDotDotToken !== undefined;
|
||||
|
||||
case SyntaxKind.SpreadElementExpression:
|
||||
// `...` in `[...a] = ...`
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the property name of a BindingElement-like element
|
||||
*/
|
||||
function getEffectivePropertyNameOfEffectiveBindingElement(bindingElement: EffectiveBindingElement) {
|
||||
switch (bindingElement.kind) {
|
||||
case SyntaxKind.BindingElement:
|
||||
// `a` in `let { a: b } = ...`
|
||||
// `[a]` in `let { [a]: b } = ...`
|
||||
// `"a"` in `let { "a": b } = ...`
|
||||
// `1` in `let { 1: b } = ...`
|
||||
if ((<BindingElement>bindingElement).propertyName) {
|
||||
return (<BindingElement>bindingElement).propertyName;
|
||||
else if (i === numElements - 1) {
|
||||
if (bindingElements) {
|
||||
flattenContext.emitBindingOrAssignment(flattenContext.createObjectBindingOrAssignmentPattern(bindingElements), value, location, pattern);
|
||||
bindingElements = undefined;
|
||||
}
|
||||
const rhsValue = createRestCall(flattenContext.context, value, elements, computedTempVariables, pattern);
|
||||
flattenBindingOrAssignmentElement(flattenContext, element, rhsValue, element);
|
||||
}
|
||||
}
|
||||
if (bindingElements) {
|
||||
flattenContext.emitBindingOrAssignment(flattenContext.createObjectBindingOrAssignmentPattern(bindingElements), value, location, pattern);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
/**
|
||||
* Flattens an ArrayBindingOrAssignmentPattern into zero or more bindings or assignments.
|
||||
*
|
||||
* @param flattenContext Options used to control flattening.
|
||||
* @param parent The parent element of the pattern.
|
||||
* @param pattern The ArrayBindingOrAssignmentPattern to flatten.
|
||||
* @param value The current RHS value to assign to the element.
|
||||
* @param location The location to use for source maps and comments.
|
||||
*/
|
||||
function flattenArrayBindingOrAssignmentPattern(flattenContext: FlattenContext, parent: BindingOrAssignmentElement, pattern: ArrayBindingOrAssignmentPattern, value: Expression, location: TextRange) {
|
||||
const elements = getElementsOfBindingOrAssignmentPattern(pattern);
|
||||
const numElements = elements.length;
|
||||
if (flattenContext.level < FlattenLevel.ObjectRest && !isArrayLiteralExpression(value)) {
|
||||
// Read the elements of the iterable into an array
|
||||
value = ensureIdentifier(
|
||||
flattenContext,
|
||||
createReadHelper(
|
||||
flattenContext.context,
|
||||
value,
|
||||
numElements > 0 && getRestIndicatorOfBindingOrAssignmentElement(elements[numElements - 1])
|
||||
? undefined
|
||||
: numElements,
|
||||
location
|
||||
),
|
||||
/*reuseIdentifierExpressions*/ false,
|
||||
location
|
||||
);
|
||||
}
|
||||
else if (numElements !== 1 && (flattenContext.level < FlattenLevel.ObjectRest || numElements === 0)) {
|
||||
// For anything other than a single-element destructuring we need to generate a temporary
|
||||
// to ensure value is evaluated exactly once. Additionally, if we have zero elements
|
||||
// we need to emit *something* to ensure that in case a 'var' keyword was already emitted,
|
||||
// so in that case, we'll intentionally create that temporary.
|
||||
const reuseIdentifierExpressions = !isDeclarationBindingElement(parent) || numElements !== 0;
|
||||
value = ensureIdentifier(flattenContext, value, reuseIdentifierExpressions, location);
|
||||
}
|
||||
let bindingElements: BindingOrAssignmentElement[];
|
||||
let restContainingElements: [Identifier, BindingOrAssignmentElement][];
|
||||
for (let i = 0; i < numElements; i++) {
|
||||
const element = elements[i];
|
||||
if (flattenContext.level >= FlattenLevel.ObjectRest) {
|
||||
// If an array pattern contains an ObjectRest, we must cache the result so that we
|
||||
// can perform the ObjectRest destructuring in a different declaration
|
||||
if (element.transformFlags & TransformFlags.ContainsObjectRest) {
|
||||
const temp = createTempVariable(/*recordTempVariable*/ undefined);
|
||||
if (flattenContext.hoistTempVariables) {
|
||||
flattenContext.context.hoistVariableDeclaration(temp);
|
||||
}
|
||||
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
// `a` in `({ a: b } = ...)`
|
||||
// `[a]` in `({ [a]: b } = ...)`
|
||||
// `"a"` in `({ "a": b } = ...)`
|
||||
// `1` in `({ 1: b } = ...)`
|
||||
if ((<PropertyAssignment>bindingElement).name) {
|
||||
return (<PropertyAssignment>bindingElement).name;
|
||||
restContainingElements = append(restContainingElements, <[Identifier, BindingOrAssignmentElement]>[temp, element]);
|
||||
bindingElements = append(bindingElements, flattenContext.createArrayBindingOrAssignmentElement(temp));
|
||||
}
|
||||
|
||||
break;
|
||||
else {
|
||||
bindingElements = append(bindingElements, element);
|
||||
}
|
||||
}
|
||||
else if (isOmittedExpression(element)) {
|
||||
continue;
|
||||
}
|
||||
else if (!getRestIndicatorOfBindingOrAssignmentElement(element)) {
|
||||
const rhsValue = createElementAccess(value, i);
|
||||
flattenBindingOrAssignmentElement(flattenContext, element, rhsValue, /*location*/ element);
|
||||
}
|
||||
else if (i === numElements - 1) {
|
||||
const rhsValue = createArraySlice(value, i);
|
||||
flattenBindingOrAssignmentElement(flattenContext, element, rhsValue, /*location*/ element);
|
||||
}
|
||||
}
|
||||
|
||||
const target = getTargetOfEffectiveBindingElement(bindingElement);
|
||||
if (target && isPropertyName(target)) {
|
||||
return target;
|
||||
if (bindingElements) {
|
||||
flattenContext.emitBindingOrAssignment(flattenContext.createArrayBindingOrAssignmentPattern(bindingElements), value, location, pattern);
|
||||
}
|
||||
|
||||
Debug.fail("Invalid property name for binding element.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a node is BindingPattern-like
|
||||
*/
|
||||
function isEffectiveBindingPattern(node: EffectiveBindingTarget): node is EffectiveBindingPattern {
|
||||
return isEffectiveObjectBindingPattern(node)
|
||||
|| isEffectiveArrayBindingPattern(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a node is ObjectBindingPattern-like
|
||||
*/
|
||||
function isEffectiveObjectBindingPattern(node: EffectiveBindingTarget): node is EffectiveObjectBindingPattern {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ObjectBindingPattern:
|
||||
case SyntaxKind.ObjectLiteralExpression:
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a node is ArrayBindingPattern-like
|
||||
*/
|
||||
function isEffectiveArrayBindingPattern(node: EffectiveBindingTarget): node is EffectiveArrayBindingPattern {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ArrayBindingPattern:
|
||||
case SyntaxKind.ArrayLiteralExpression:
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the elements of a BindingPattern-like name
|
||||
*/
|
||||
function getElementsOfEffectiveBindingPattern(name: EffectiveBindingPattern): EffectiveBindingElement[] {
|
||||
switch (name.kind) {
|
||||
case SyntaxKind.ObjectBindingPattern:
|
||||
case SyntaxKind.ArrayBindingPattern:
|
||||
// `a` in `{a}`
|
||||
// `a` in `[a]`
|
||||
return name.elements;
|
||||
|
||||
case SyntaxKind.ObjectLiteralExpression:
|
||||
// `a` in `{a}`
|
||||
return name.properties;
|
||||
|
||||
case SyntaxKind.ArrayLiteralExpression:
|
||||
// `a` in `[a]`
|
||||
return name.elements;
|
||||
if (restContainingElements) {
|
||||
for (const [id, element] of restContainingElements) {
|
||||
flattenBindingOrAssignmentElement(flattenContext, element, id, element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an expression used to provide a default value if a value is `undefined` at runtime.
|
||||
*
|
||||
* @param flattenContext Options used to control flattening.
|
||||
* @param value The RHS value to test.
|
||||
* @param defaultValue The default value to use if `value` is `undefined` at runtime.
|
||||
* @param location The location to use for source maps and comments.
|
||||
*/
|
||||
function createDefaultValueCheck(value: Expression, defaultValue: Expression, location: TextRange, emitTempVariableAssignment: (value: Expression, location: TextRange) => Identifier): Expression {
|
||||
value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true, emitTempVariableAssignment, location);
|
||||
return createConditional(
|
||||
createStrictEquality(value, createVoidZero()),
|
||||
createToken(SyntaxKind.QuestionToken),
|
||||
defaultValue,
|
||||
createToken(SyntaxKind.ColonToken),
|
||||
value
|
||||
);
|
||||
function createDefaultValueCheck(flattenContext: FlattenContext, value: Expression, defaultValue: Expression, location: TextRange): Expression {
|
||||
value = ensureIdentifier(flattenContext, value, /*reuseIdentifierExpressions*/ true, location);
|
||||
return createConditional(createTypeCheck(value, "undefined"), defaultValue, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates either a PropertyAccessExpression or an ElementAccessExpression for the
|
||||
* right-hand side of a transformed destructuring assignment.
|
||||
*
|
||||
* @param expression The right-hand expression that is the source of the property.
|
||||
* @link https://tc39.github.io/ecma262/#sec-runtime-semantics-keyeddestructuringassignmentevaluation
|
||||
*
|
||||
* @param flattenContext Options used to control flattening.
|
||||
* @param value The RHS value that is the source of the property.
|
||||
* @param propertyName The destructuring property name.
|
||||
* @param emitTempVariableAssignment A callback used to emit a temporary variable.
|
||||
*/
|
||||
function createDestructuringPropertyAccess(expression: Expression, propertyName: PropertyName, emitTempVariableAssignment: (value: Expression, location: TextRange) => Identifier): LeftHandSideExpression {
|
||||
function createDestructuringPropertyAccess(flattenContext: FlattenContext, value: Expression, propertyName: PropertyName): LeftHandSideExpression {
|
||||
if (isComputedPropertyName(propertyName)) {
|
||||
const argumentExpression = ensureIdentifier(propertyName.expression, /*reuseIdentifierExpressions*/ false, emitTempVariableAssignment, /*location*/ propertyName);
|
||||
return createElementAccess(expression, argumentExpression);
|
||||
const argumentExpression = ensureIdentifier(flattenContext, propertyName.expression, /*reuseIdentifierExpressions*/ false, /*location*/ propertyName);
|
||||
return createElementAccess(value, argumentExpression);
|
||||
}
|
||||
else if (isLiteralExpression(propertyName)) {
|
||||
else if (isStringOrNumericLiteral(propertyName)) {
|
||||
const argumentExpression = getSynthesizedClone(propertyName);
|
||||
argumentExpression.text = unescapeIdentifier(argumentExpression.text);
|
||||
return createElementAccess(expression, argumentExpression);
|
||||
}
|
||||
else if (isGeneratedIdentifier(propertyName)) {
|
||||
const name = getSynthesizedClone(propertyName);
|
||||
name.text = unescapeIdentifier(name.text);
|
||||
return createPropertyAccess(expression, name);
|
||||
return createElementAccess(value, argumentExpression);
|
||||
}
|
||||
else {
|
||||
const name = createIdentifier(unescapeIdentifier(propertyName.text));
|
||||
return createPropertyAccess(expression, name);
|
||||
return createPropertyAccess(value, name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -609,23 +418,96 @@ namespace ts {
|
||||
* This function is useful to ensure that the expression's value can be read from in subsequent expressions.
|
||||
* Unless 'reuseIdentifierExpressions' is false, 'value' will be returned if it is just an identifier.
|
||||
*
|
||||
* @param flattenContext Options used to control flattening.
|
||||
* @param value the expression whose value needs to be bound.
|
||||
* @param reuseIdentifierExpressions true if identifier expressions can simply be returned;
|
||||
* false if it is necessary to always emit an identifier.
|
||||
* @param emitTempVariableAssignment A callback used to emit a temporary variable.
|
||||
* @param location The location to use for source maps and comments.
|
||||
*/
|
||||
function ensureIdentifier(
|
||||
value: Expression,
|
||||
reuseIdentifierExpressions: boolean,
|
||||
emitTempVariableAssignment: (value: Expression, location: TextRange) => Identifier,
|
||||
location: TextRange) {
|
||||
|
||||
function ensureIdentifier(flattenContext: FlattenContext, value: Expression, reuseIdentifierExpressions: boolean, location: TextRange) {
|
||||
if (isIdentifier(value) && reuseIdentifierExpressions) {
|
||||
return value;
|
||||
}
|
||||
else {
|
||||
return emitTempVariableAssignment(value, location);
|
||||
const temp = createTempVariable(/*recordTempVariable*/ undefined);
|
||||
if (flattenContext.hoistTempVariables) {
|
||||
flattenContext.context.hoistVariableDeclaration(temp);
|
||||
flattenContext.emitExpression(createAssignment(temp, value, location));
|
||||
}
|
||||
else {
|
||||
flattenContext.emitBindingOrAssignment(temp, value, location, /*original*/ undefined);
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
||||
function makeArrayBindingPattern(elements: BindingOrAssignmentElement[]) {
|
||||
Debug.assertEachNode(elements, isArrayBindingElement);
|
||||
return createArrayBindingPattern(<ArrayBindingElement[]>elements);
|
||||
}
|
||||
|
||||
function makeArrayAssignmentPattern(elements: BindingOrAssignmentElement[]) {
|
||||
return createArrayLiteral(map(elements, convertToArrayAssignmentElement));
|
||||
}
|
||||
|
||||
function makeObjectBindingPattern(elements: BindingOrAssignmentElement[]) {
|
||||
Debug.assertEachNode(elements, isBindingElement);
|
||||
return createObjectBindingPattern(<BindingElement[]>elements);
|
||||
}
|
||||
|
||||
function makeObjectAssignmentPattern(elements: BindingOrAssignmentElement[]) {
|
||||
return createObjectLiteral(map(elements, convertToObjectAssignmentElement));
|
||||
}
|
||||
|
||||
function makeBindingElement(name: Identifier) {
|
||||
return createBindingElement(/*propertyName*/ undefined, /*dotDotDotToken*/ undefined, name);
|
||||
}
|
||||
|
||||
function makeAssignmentElement(name: Identifier) {
|
||||
return name;
|
||||
}
|
||||
|
||||
const restHelper: EmitHelper = {
|
||||
name: "typescript:rest",
|
||||
scoped: false,
|
||||
text: `
|
||||
var __rest = (this && this.__rest) || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||
t[p] = s[p];
|
||||
if (typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
|
||||
t[p[i]] = s[p[i]];
|
||||
return t;
|
||||
};`
|
||||
};
|
||||
|
||||
/** Given value: o, propName: p, pattern: { a, b, ...p } from the original statement
|
||||
* `{ a, b, ...p } = o`, create `p = __rest(o, ["a", "b"]);`*/
|
||||
function createRestCall(context: TransformationContext, value: Expression, elements: BindingOrAssignmentElement[], computedTempVariables: Expression[], location: TextRange): Expression {
|
||||
context.requestEmitHelper(restHelper);
|
||||
const propertyNames: Expression[] = [];
|
||||
let computedTempVariableOffset = 0;
|
||||
for (let i = 0; i < elements.length - 1; i++) {
|
||||
const propertyName = getPropertyNameOfBindingOrAssignmentElement(elements[i]);
|
||||
if (propertyName) {
|
||||
if (isComputedPropertyName(propertyName)) {
|
||||
const temp = computedTempVariables[computedTempVariableOffset];
|
||||
computedTempVariableOffset++;
|
||||
// typeof _tmp === "symbol" ? _tmp : _tmp + ""
|
||||
propertyNames.push(
|
||||
createConditional(
|
||||
createTypeCheck(temp, "symbol"),
|
||||
temp,
|
||||
createAdd(temp, createLiteral(""))
|
||||
)
|
||||
);
|
||||
}
|
||||
else {
|
||||
propertyNames.push(createLiteral(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
||||
return createCall(getHelperName("__rest"), undefined, [value, createArrayLiteral(propertyNames, location)]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -466,8 +466,8 @@ namespace ts {
|
||||
case SyntaxKind.YieldExpression:
|
||||
return visitYieldExpression(<YieldExpression>node);
|
||||
|
||||
case SyntaxKind.SpreadElementExpression:
|
||||
return visitSpreadElementExpression(<SpreadElementExpression>node);
|
||||
case SyntaxKind.SpreadElement:
|
||||
return visitSpreadElement(<SpreadElement>node);
|
||||
|
||||
case SyntaxKind.SuperKeyword:
|
||||
return visitSuperKeyword();
|
||||
@@ -842,14 +842,14 @@ namespace ts {
|
||||
* @param hasSynthesizedSuper A value indicating whether the constructor starts with a
|
||||
* synthesized `super` call.
|
||||
*/
|
||||
function transformConstructorParameters(constructor: ConstructorDeclaration, hasSynthesizedSuper: boolean): ParameterDeclaration[] {
|
||||
function transformConstructorParameters(constructor: ConstructorDeclaration, hasSynthesizedSuper: boolean) {
|
||||
// If the TypeScript transformer needed to synthesize a constructor for property
|
||||
// initializers, it would have also added a synthetic `...args` parameter and
|
||||
// `super` call.
|
||||
// If this is the case, we do not include the synthetic `...args` parameter and
|
||||
// will instead use the `arguments` object in ES5/3.
|
||||
return visitParameterList(constructor && !hasSynthesizedSuper && constructor.parameters, visitor, context)
|
||||
|| [];
|
||||
|| <ParameterDeclaration[]>[];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1029,7 +1029,20 @@ namespace ts {
|
||||
|
||||
// Return the result if we have an immediate super() call on the last statement.
|
||||
if (superCallExpression && statementOffset === ctorStatements.length - 1) {
|
||||
statements.push(createReturn(superCallExpression));
|
||||
const returnStatement = createReturn(superCallExpression);
|
||||
|
||||
if (superCallExpression.kind !== SyntaxKind.BinaryExpression
|
||||
|| (superCallExpression as BinaryExpression).left.kind !== SyntaxKind.CallExpression) {
|
||||
Debug.fail("Assumed generated super call would have form 'super.call(...) || this'.");
|
||||
}
|
||||
|
||||
// Shift comments from the original super call to the return statement.
|
||||
setCommentRange(returnStatement, getCommentRange(
|
||||
setEmitFlags(
|
||||
(superCallExpression as BinaryExpression).left,
|
||||
EmitFlags.NoComments)));
|
||||
|
||||
statements.push(returnStatement);
|
||||
return SuperCaptureResult.ReplaceWithReturn;
|
||||
}
|
||||
|
||||
@@ -1163,12 +1176,13 @@ namespace ts {
|
||||
createVariableStatement(
|
||||
/*modifiers*/ undefined,
|
||||
createVariableDeclarationList(
|
||||
flattenDestructuring(
|
||||
context,
|
||||
flattenDestructuringBinding(
|
||||
parameter,
|
||||
temp,
|
||||
/*recordTempVariablesInLine*/ true,
|
||||
visitor)
|
||||
visitor,
|
||||
context,
|
||||
FlattenLevel.All,
|
||||
temp
|
||||
)
|
||||
)
|
||||
),
|
||||
EmitFlags.CustomPrologue
|
||||
@@ -1201,10 +1215,7 @@ namespace ts {
|
||||
function addDefaultValueAssignmentForInitializer(statements: Statement[], parameter: ParameterDeclaration, name: Identifier, initializer: Expression): void {
|
||||
initializer = visitNode(initializer, visitor, isExpression);
|
||||
const statement = createIf(
|
||||
createStrictEquality(
|
||||
getSynthesizedClone(name),
|
||||
createVoidZero()
|
||||
),
|
||||
createTypeCheck(getSynthesizedClone(name), "undefined"),
|
||||
setEmitFlags(
|
||||
createBlock([
|
||||
createStatement(
|
||||
@@ -1603,13 +1614,11 @@ namespace ts {
|
||||
let statementsLocation: TextRange;
|
||||
let closeBraceLocation: TextRange;
|
||||
|
||||
let statements: Statement[] = [];
|
||||
let statementOffset: number;
|
||||
const statements: Statement[] = [];
|
||||
const body = node.body;
|
||||
let statementOffset: number;
|
||||
|
||||
// Resume the lexical environment and iterator scope started in visitParameterList
|
||||
resumeLexicalEnvironment();
|
||||
|
||||
if (isBlock(body)) {
|
||||
// ensureUseStrict is false because no new prologue-directive should be added.
|
||||
// addPrologueDirectives will simply put already-existing directives at the beginning of the target statement-array
|
||||
@@ -1663,21 +1672,15 @@ namespace ts {
|
||||
closeBraceLocation = body;
|
||||
}
|
||||
|
||||
const declarations = endLexicalEnvironment();
|
||||
addRange(statements, declarations);
|
||||
const lexicalEnvironment = context.endLexicalEnvironment();
|
||||
addRange(statements, lexicalEnvironment);
|
||||
|
||||
// If we added any final generated statements, this must be a multi-line block
|
||||
if (some(declarations)) {
|
||||
if (!multiLine && lexicalEnvironment && lexicalEnvironment.length) {
|
||||
multiLine = true;
|
||||
}
|
||||
|
||||
const block = createBlock(
|
||||
createNodeArray(statements, statementsLocation),
|
||||
node.body,
|
||||
multiLine);
|
||||
|
||||
setOriginalNode(block, node.body);
|
||||
|
||||
const block = createBlock(createNodeArray(statements, statementsLocation), node.body, multiLine);
|
||||
if (!multiLine && singleLine) {
|
||||
setEmitFlags(block, EmitFlags.SingleLine);
|
||||
}
|
||||
@@ -1686,6 +1689,7 @@ namespace ts {
|
||||
setTokenSourceMapRange(block, SyntaxKind.CloseBraceToken, closeBraceLocation);
|
||||
}
|
||||
|
||||
setOriginalNode(block, node.body);
|
||||
return block;
|
||||
}
|
||||
|
||||
@@ -1698,16 +1702,10 @@ namespace ts {
|
||||
// If we are here it is most likely because our expression is a destructuring assignment.
|
||||
switch (node.expression.kind) {
|
||||
case SyntaxKind.ParenthesizedExpression:
|
||||
return updateStatement(node,
|
||||
visitParenthesizedExpression(<ParenthesizedExpression>node.expression, /*needsDestructuringValue*/ false)
|
||||
);
|
||||
|
||||
return updateStatement(node, visitParenthesizedExpression(<ParenthesizedExpression>node.expression, /*needsDestructuringValue*/ false));
|
||||
case SyntaxKind.BinaryExpression:
|
||||
return updateStatement(node,
|
||||
visitBinaryExpression(<BinaryExpression>node.expression, /*needsDestructuringValue*/ false)
|
||||
);
|
||||
return updateStatement(node, visitBinaryExpression(<BinaryExpression>node.expression, /*needsDestructuringValue*/ false));
|
||||
}
|
||||
|
||||
return visitEachChild(node, visitor, context);
|
||||
}
|
||||
|
||||
@@ -1726,19 +1724,11 @@ namespace ts {
|
||||
// we pass that information along to the children that care about it.
|
||||
switch (node.expression.kind) {
|
||||
case SyntaxKind.ParenthesizedExpression:
|
||||
return updateParen(
|
||||
node,
|
||||
visitParenthesizedExpression(<ParenthesizedExpression>node.expression, /*needsDestructuringValue*/ false)
|
||||
);
|
||||
|
||||
return updateParen(node, visitParenthesizedExpression(<ParenthesizedExpression>node.expression, /*needsDestructuringValue*/ false));
|
||||
case SyntaxKind.BinaryExpression:
|
||||
return updateParen(
|
||||
node,
|
||||
visitBinaryExpression(<BinaryExpression>node.expression, /*needsDestructuringValue*/ false)
|
||||
);
|
||||
return updateParen(node, visitBinaryExpression(<BinaryExpression>node.expression, /*needsDestructuringValue*/ false));
|
||||
}
|
||||
}
|
||||
|
||||
return visitEachChild(node, visitor, context);
|
||||
}
|
||||
|
||||
@@ -1752,15 +1742,13 @@ namespace ts {
|
||||
function visitBinaryExpression(node: BinaryExpression, needsDestructuringValue: boolean): Expression {
|
||||
// If we are here it is because this is a destructuring assignment.
|
||||
if (isDestructuringAssignment(node)) {
|
||||
return flattenDestructuringToExpression(
|
||||
context,
|
||||
return flattenDestructuringAssignment(
|
||||
<DestructuringAssignment>node,
|
||||
needsDestructuringValue,
|
||||
createAssignment,
|
||||
visitor
|
||||
);
|
||||
visitor,
|
||||
context,
|
||||
FlattenLevel.All,
|
||||
needsDestructuringValue);
|
||||
}
|
||||
|
||||
return visitEachChild(node, visitor, context);
|
||||
}
|
||||
|
||||
@@ -1773,12 +1761,12 @@ namespace ts {
|
||||
if (decl.initializer) {
|
||||
let assignment: Expression;
|
||||
if (isBindingPattern(decl.name)) {
|
||||
assignment = flattenDestructuringToExpression(
|
||||
context,
|
||||
assignment = flattenDestructuringAssignment(
|
||||
decl,
|
||||
/*needsValue*/ false,
|
||||
createAssignment,
|
||||
visitor);
|
||||
visitor,
|
||||
context,
|
||||
FlattenLevel.All
|
||||
);
|
||||
}
|
||||
else {
|
||||
assignment = createBinary(<Identifier>decl.name, SyntaxKind.EqualsToken, visitNode(decl.initializer, visitor, isExpression));
|
||||
@@ -1931,14 +1919,16 @@ namespace ts {
|
||||
function visitVariableDeclaration(node: VariableDeclaration): VisitResult<VariableDeclaration> {
|
||||
// If we are here it is because the name contains a binding pattern.
|
||||
if (isBindingPattern(node.name)) {
|
||||
const recordTempVariablesInLine = !enclosingVariableStatement
|
||||
|| !hasModifier(enclosingVariableStatement, ModifierFlags.Export);
|
||||
return flattenDestructuring(
|
||||
context,
|
||||
const hoistTempVariables = enclosingVariableStatement
|
||||
&& hasModifier(enclosingVariableStatement, ModifierFlags.Export);
|
||||
return flattenDestructuringBinding(
|
||||
node,
|
||||
visitor,
|
||||
context,
|
||||
FlattenLevel.All,
|
||||
/*value*/ undefined,
|
||||
recordTempVariablesInLine,
|
||||
visitor);
|
||||
hoistTempVariables
|
||||
);
|
||||
}
|
||||
|
||||
return visitEachChild(node, visitor, context);
|
||||
@@ -1957,6 +1947,7 @@ namespace ts {
|
||||
|
||||
let result: VisitResult<Statement>;
|
||||
if (isIterationStatement(enclosedStatement.statement, /*lookInLabeledStatements*/ false)) {
|
||||
const savedEnclosingLabeledStatements = enclosingLabeledStatements;
|
||||
enclosingLabeledStatements = enclosedStatement.enclosingLabeledStatements;
|
||||
if (shouldConvertIterationStatementBody(enclosedStatement.statement)) {
|
||||
result = visitNodes(createNodeArray([enclosedStatement.statement]), visitor, isStatement);
|
||||
@@ -1966,6 +1957,8 @@ namespace ts {
|
||||
result = restoreEnclosingLabels(visitNode(enclosedStatement.statement, visitor, isStatement), enclosingLabeledStatements);
|
||||
enclosingLabeledStatements = undefined;
|
||||
}
|
||||
|
||||
enclosingLabeledStatements = savedEnclosingLabeledStatements;
|
||||
}
|
||||
else {
|
||||
result = restoreEnclosingLabels(visitNode(enclosedStatement.statement, visitor, isStatement), enclosedStatement.enclosingLabeledStatements);
|
||||
@@ -2015,12 +2008,12 @@ namespace ts {
|
||||
if (firstOriginalDeclaration && isBindingPattern(firstOriginalDeclaration.name)) {
|
||||
// This works whether the declaration is a var, let, or const.
|
||||
// It will use rhsIterationValue _a[_i] as the initializer.
|
||||
const declarations = flattenDestructuring(
|
||||
context,
|
||||
const declarations = flattenDestructuringBinding(
|
||||
firstOriginalDeclaration,
|
||||
boundValue,
|
||||
/*recordTempVariablesInLine*/ true,
|
||||
visitor
|
||||
visitor,
|
||||
context,
|
||||
FlattenLevel.All,
|
||||
boundValue
|
||||
);
|
||||
|
||||
const declarationList = createVariableDeclarationList(declarations, /*location*/ node.initializer);
|
||||
@@ -2888,13 +2881,13 @@ namespace ts {
|
||||
|
||||
const temp = createTempVariable(undefined);
|
||||
const newVariableDeclaration = createVariableDeclaration(temp, undefined, undefined, node.variableDeclaration);
|
||||
|
||||
const vars = flattenDestructuring(
|
||||
context,
|
||||
const vars = flattenDestructuringBinding(
|
||||
node.variableDeclaration,
|
||||
temp,
|
||||
/*recordTempVariablesInLine*/ true,
|
||||
visitor);
|
||||
visitor,
|
||||
context,
|
||||
FlattenLevel.All,
|
||||
temp
|
||||
);
|
||||
const list = createVariableDeclarationList(vars, /*location*/ node.variableDeclaration, /*flags*/ node.variableDeclaration.flags);
|
||||
const destructure = createVariableStatement(undefined, list);
|
||||
|
||||
@@ -2981,7 +2974,7 @@ namespace ts {
|
||||
setEmitFlags(thisArg, EmitFlags.NoSubstitution);
|
||||
}
|
||||
let resultingCall: CallExpression | BinaryExpression;
|
||||
if (node.transformFlags & TransformFlags.ContainsSpreadElementExpression) {
|
||||
if (node.transformFlags & TransformFlags.ContainsSpread) {
|
||||
// [source]
|
||||
// f(...a, b)
|
||||
// x.m(...a, b)
|
||||
@@ -3043,7 +3036,7 @@ namespace ts {
|
||||
*/
|
||||
function visitNewExpression(node: NewExpression): LeftHandSideExpression {
|
||||
// We are here because we contain a SpreadElementExpression.
|
||||
Debug.assert((node.transformFlags & TransformFlags.ContainsSpreadElementExpression) !== 0);
|
||||
Debug.assert((node.transformFlags & TransformFlags.ContainsSpread) !== 0);
|
||||
|
||||
// [source]
|
||||
// new C(...a)
|
||||
@@ -3064,7 +3057,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms an array of Expression nodes that contains a SpreadElementExpression.
|
||||
* Transforms an array of Expression nodes that contains a SpreadExpression.
|
||||
*
|
||||
* @param elements The array of Expression nodes.
|
||||
* @param needsUniqueCopy A value indicating whether to ensure that the result is a fresh array.
|
||||
@@ -3081,7 +3074,7 @@ namespace ts {
|
||||
// expressions into an array literal.
|
||||
const numElements = elements.length;
|
||||
const segments = flatten(
|
||||
spanMap(elements, partitionSpreadElement, (partition, visitPartition, _start, end) =>
|
||||
spanMap(elements, partitionSpread, (partition, visitPartition, _start, end) =>
|
||||
visitPartition(partition, multiLine, hasTrailingComma && end === numElements)
|
||||
)
|
||||
);
|
||||
@@ -3099,17 +3092,17 @@ namespace ts {
|
||||
return createSpreadHelper(context, segments);
|
||||
}
|
||||
|
||||
function partitionSpreadElement(node: Expression) {
|
||||
return isSpreadElementExpression(node)
|
||||
? visitSpanOfSpreadElements
|
||||
: visitSpanOfNonSpreadElements;
|
||||
function partitionSpread(node: Expression) {
|
||||
return isSpreadExpression(node)
|
||||
? visitSpanOfSpreads
|
||||
: visitSpanOfNonSpreads;
|
||||
}
|
||||
|
||||
function visitSpanOfSpreadElements(chunk: Expression[]): VisitResult<Expression> {
|
||||
return map(chunk, visitSpreadElementExpression);
|
||||
function visitSpanOfSpreads(chunk: Expression[]): VisitResult<Expression> {
|
||||
return map(chunk, visitExpressionOfSpread);
|
||||
}
|
||||
|
||||
function visitSpanOfNonSpreadElements(chunk: Expression[], multiLine: boolean, hasTrailingComma: boolean): VisitResult<Expression> {
|
||||
function visitSpanOfNonSpreads(chunk: Expression[], multiLine: boolean, hasTrailingComma: boolean): VisitResult<Expression> {
|
||||
return createArrayLiteral(
|
||||
visitNodes(createNodeArray(chunk, /*location*/ undefined, hasTrailingComma), visitor, isExpression),
|
||||
/*location*/ undefined,
|
||||
@@ -3117,12 +3110,16 @@ namespace ts {
|
||||
);
|
||||
}
|
||||
|
||||
function visitSpreadElement(node: SpreadElement) {
|
||||
return visitNode(node.expression, visitor, isExpression);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the expression of a SpreadElementExpression node.
|
||||
* Transforms the expression of a SpreadExpression node.
|
||||
*
|
||||
* @param node A SpreadElementExpression node.
|
||||
* @param node A SpreadExpression node.
|
||||
*/
|
||||
function visitSpreadElementExpression(node: SpreadElementExpression) {
|
||||
function visitExpressionOfSpread(node: SpreadElement) {
|
||||
return visitNode(node.expression, visitor, isExpression);
|
||||
}
|
||||
|
||||
@@ -3484,11 +3481,11 @@ namespace ts {
|
||||
}
|
||||
|
||||
const callArgument = singleOrUndefined((<CallExpression>statementExpression).arguments);
|
||||
if (!callArgument || !nodeIsSynthesized(callArgument) || callArgument.kind !== SyntaxKind.SpreadElementExpression) {
|
||||
if (!callArgument || !nodeIsSynthesized(callArgument) || callArgument.kind !== SyntaxKind.SpreadElement) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const expression = (<SpreadElementExpression>callArgument).expression;
|
||||
const expression = (<SpreadElement>callArgument).expression;
|
||||
return isIdentifier(expression) && expression.text === "arguments";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,85 +17,75 @@ namespace ts {
|
||||
}
|
||||
|
||||
function visitor(node: Node): VisitResult<Node> {
|
||||
if (node.transformFlags & TransformFlags.ES2016) {
|
||||
return visitorWorker(node);
|
||||
}
|
||||
else if (node.transformFlags & TransformFlags.ContainsES2016) {
|
||||
return visitEachChild(node, visitor, context);
|
||||
}
|
||||
else {
|
||||
if ((node.transformFlags & TransformFlags.ContainsES2016) === 0) {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
function visitorWorker(node: Node): VisitResult<Node> {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.BinaryExpression:
|
||||
return visitBinaryExpression(<BinaryExpression>node);
|
||||
|
||||
default:
|
||||
Debug.failBadSyntaxKind(node);
|
||||
return visitEachChild(node, visitor, context);
|
||||
}
|
||||
}
|
||||
|
||||
function visitBinaryExpression(node: BinaryExpression): Expression {
|
||||
// We are here because ES2016 adds support for the exponentiation operator.
|
||||
switch (node.operatorToken.kind) {
|
||||
case SyntaxKind.AsteriskAsteriskEqualsToken:
|
||||
return visitExponentiationAssignmentExpression(node);
|
||||
case SyntaxKind.AsteriskAsteriskToken:
|
||||
return visitExponentiationExpression(node);
|
||||
default:
|
||||
return visitEachChild(node, visitor, context);
|
||||
}
|
||||
}
|
||||
|
||||
function visitExponentiationAssignmentExpression(node: BinaryExpression) {
|
||||
let target: Expression;
|
||||
let value: Expression;
|
||||
const left = visitNode(node.left, visitor, isExpression);
|
||||
const right = visitNode(node.right, visitor, isExpression);
|
||||
if (node.operatorToken.kind === SyntaxKind.AsteriskAsteriskEqualsToken) {
|
||||
let target: Expression;
|
||||
let value: Expression;
|
||||
if (isElementAccessExpression(left)) {
|
||||
// Transforms `a[x] **= b` into `(_a = a)[_x = x] = Math.pow(_a[_x], b)`
|
||||
const expressionTemp = createTempVariable(hoistVariableDeclaration);
|
||||
|
||||
const argumentExpressionTemp = createTempVariable(hoistVariableDeclaration);
|
||||
|
||||
target = createElementAccess(
|
||||
createAssignment(expressionTemp, left.expression, /*location*/ left.expression),
|
||||
createAssignment(argumentExpressionTemp, left.argumentExpression, /*location*/ left.argumentExpression),
|
||||
/*location*/ left
|
||||
);
|
||||
|
||||
value = createElementAccess(
|
||||
expressionTemp,
|
||||
argumentExpressionTemp,
|
||||
/*location*/ left
|
||||
);
|
||||
}
|
||||
else if (isPropertyAccessExpression(left)) {
|
||||
// Transforms `a.x **= b` into `(_a = a).x = Math.pow(_a.x, b)`
|
||||
const expressionTemp = createTempVariable(hoistVariableDeclaration);
|
||||
|
||||
target = createPropertyAccess(
|
||||
createAssignment(expressionTemp, left.expression, /*location*/ left.expression),
|
||||
left.name,
|
||||
/*location*/ left
|
||||
);
|
||||
|
||||
value = createPropertyAccess(
|
||||
expressionTemp,
|
||||
left.name,
|
||||
/*location*/ left
|
||||
);
|
||||
}
|
||||
else {
|
||||
// Transforms `a **= b` into `a = Math.pow(a, b)`
|
||||
target = left;
|
||||
value = left;
|
||||
}
|
||||
|
||||
return createAssignment(target, createMathPow(value, right, /*location*/ node), /*location*/ node);
|
||||
if (isElementAccessExpression(left)) {
|
||||
// Transforms `a[x] **= b` into `(_a = a)[_x = x] = Math.pow(_a[_x], b)`
|
||||
const expressionTemp = createTempVariable(hoistVariableDeclaration);
|
||||
const argumentExpressionTemp = createTempVariable(hoistVariableDeclaration);
|
||||
target = createElementAccess(
|
||||
createAssignment(expressionTemp, left.expression, /*location*/ left.expression),
|
||||
createAssignment(argumentExpressionTemp, left.argumentExpression, /*location*/ left.argumentExpression),
|
||||
/*location*/ left
|
||||
);
|
||||
value = createElementAccess(
|
||||
expressionTemp,
|
||||
argumentExpressionTemp,
|
||||
/*location*/ left
|
||||
);
|
||||
}
|
||||
else if (node.operatorToken.kind === SyntaxKind.AsteriskAsteriskToken) {
|
||||
// Transforms `a ** b` into `Math.pow(a, b)`
|
||||
return createMathPow(left, right, /*location*/ node);
|
||||
else if (isPropertyAccessExpression(left)) {
|
||||
// Transforms `a.x **= b` into `(_a = a).x = Math.pow(_a.x, b)`
|
||||
const expressionTemp = createTempVariable(hoistVariableDeclaration);
|
||||
target = createPropertyAccess(
|
||||
createAssignment(expressionTemp, left.expression, /*location*/ left.expression),
|
||||
left.name,
|
||||
/*location*/ left
|
||||
);
|
||||
value = createPropertyAccess(
|
||||
expressionTemp,
|
||||
left.name,
|
||||
/*location*/ left
|
||||
);
|
||||
}
|
||||
else {
|
||||
Debug.failBadSyntaxKind(node);
|
||||
return visitEachChild(node, visitor, context);
|
||||
// Transforms `a **= b` into `a = Math.pow(a, b)`
|
||||
target = left;
|
||||
value = left;
|
||||
}
|
||||
return createAssignment(target, createMathPow(value, right, /*location*/ node), /*location*/ node);
|
||||
}
|
||||
|
||||
function visitExponentiationExpression(node: BinaryExpression) {
|
||||
// Transforms `a ** b` into `Math.pow(a, b)`
|
||||
const left = visitNode(node.left, visitor, isExpression);
|
||||
const right = visitNode(node.right, visitor, isExpression);
|
||||
return createMathPow(left, right, /*location*/ node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,12 +31,6 @@ namespace ts {
|
||||
*/
|
||||
let enabledSubstitutions: ES2017SubstitutionFlags;
|
||||
|
||||
/**
|
||||
* Keeps track of whether we are within any containing namespaces when performing
|
||||
* just-in-time substitution while printing an expression identifier.
|
||||
*/
|
||||
let applicableSubstitutions: ES2017SubstitutionFlags;
|
||||
|
||||
/**
|
||||
* This keeps track of containers where `super` is valid, for use with
|
||||
* just-in-time substitution for `super` expressions inside of async methods.
|
||||
@@ -69,59 +63,59 @@ namespace ts {
|
||||
}
|
||||
|
||||
function visitor(node: Node): VisitResult<Node> {
|
||||
if (node.transformFlags & TransformFlags.ContainsES2017) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.AsyncKeyword:
|
||||
// ES2017 async modifier should be elided for targets < ES2017
|
||||
return undefined;
|
||||
|
||||
case SyntaxKind.AwaitExpression:
|
||||
// ES2017 'await' expressions must be transformed for targets < ES2017.
|
||||
return visitAwaitExpression(<AwaitExpression>node);
|
||||
|
||||
case SyntaxKind.YieldExpression:
|
||||
// ES2017 'yield' expressions in an async generator must be transformed
|
||||
// for targets < ES2017.
|
||||
return visitYieldExpression(<YieldExpression>node);
|
||||
|
||||
case SyntaxKind.LabeledStatement:
|
||||
return visitLabeledStatement(<LabeledStatement>node);
|
||||
|
||||
case SyntaxKind.ForOfStatement:
|
||||
// ES2017 'for-await-of' statements must be transformed for targets <
|
||||
// ES2017.
|
||||
return visitForOfStatement(<ForOfStatement>node, /*enclosingLabeledStatements*/ undefined);
|
||||
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
// ES2017 method declarations may be 'async'
|
||||
return visitMethodDeclaration(<MethodDeclaration>node);
|
||||
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
// ES2017 function declarations may be 'async'
|
||||
return visitFunctionDeclaration(<FunctionDeclaration>node);
|
||||
|
||||
case SyntaxKind.FunctionExpression:
|
||||
// ES2017 function expressions may be 'async'
|
||||
return visitFunctionExpression(<FunctionExpression>node);
|
||||
|
||||
case SyntaxKind.ArrowFunction:
|
||||
// ES2017 arrow functions may be 'async'
|
||||
return visitArrowFunction(<ArrowFunction>node);
|
||||
|
||||
case SyntaxKind.Constructor:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetKeyword:
|
||||
const savedEnclosingFunctionFlags = enclosingFunctionFlags;
|
||||
enclosingFunctionFlags = getFunctionFlags(<FunctionLikeDeclaration>node);
|
||||
const visited = visitEachChild(node, visitor, context);
|
||||
enclosingFunctionFlags = savedEnclosingFunctionFlags;
|
||||
return visited;
|
||||
|
||||
default:
|
||||
return visitEachChild(node, visitor, context);
|
||||
}
|
||||
if ((node.transformFlags & TransformFlags.ContainsES2017) === 0) {
|
||||
return node;
|
||||
}
|
||||
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.AsyncKeyword:
|
||||
// ES2017 async modifier should be elided for targets < ES2017
|
||||
return undefined;
|
||||
|
||||
case SyntaxKind.AwaitExpression:
|
||||
// ES2017 'await' expressions must be transformed for targets < ES2017.
|
||||
return visitAwaitExpression(<AwaitExpression>node);
|
||||
case SyntaxKind.YieldExpression:
|
||||
// ES2017 'yield' expressions in an async generator must be transformed
|
||||
// for targets < ES2017.
|
||||
return visitYieldExpression(<YieldExpression>node);
|
||||
|
||||
case SyntaxKind.LabeledStatement:
|
||||
return visitLabeledStatement(<LabeledStatement>node);
|
||||
|
||||
case SyntaxKind.ForOfStatement:
|
||||
// ES2017 'for-await-of' statements must be transformed for targets <
|
||||
// ES2017.
|
||||
return visitForOfStatement(<ForOfStatement>node, /*enclosingLabeledStatements*/ undefined);
|
||||
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
// ES2017 method declarations may be 'async'
|
||||
return visitMethodDeclaration(<MethodDeclaration>node);
|
||||
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
// ES2017 function declarations may be 'async'
|
||||
return visitFunctionDeclaration(<FunctionDeclaration>node);
|
||||
|
||||
case SyntaxKind.FunctionExpression:
|
||||
// ES2017 function expressions may be 'async'
|
||||
return visitFunctionExpression(<FunctionExpression>node);
|
||||
|
||||
case SyntaxKind.ArrowFunction:
|
||||
// ES2017 arrow functions may be 'async'
|
||||
return visitArrowFunction(<ArrowFunction>node);
|
||||
|
||||
case SyntaxKind.Constructor:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetKeyword:
|
||||
const savedEnclosingFunctionFlags = enclosingFunctionFlags;
|
||||
enclosingFunctionFlags = getFunctionFlags(<FunctionLikeDeclaration>node);
|
||||
const visited = visitEachChild(node, visitor, context);
|
||||
enclosingFunctionFlags = savedEnclosingFunctionFlags;
|
||||
return visited;
|
||||
|
||||
default:
|
||||
return visitEachChild(node, visitor, context);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -483,6 +477,8 @@ namespace ts {
|
||||
function transformAsyncFunctionBody(node: MethodDeclaration | AccessorDeclaration | FunctionDeclaration | FunctionExpression): FunctionBody;
|
||||
function transformAsyncFunctionBody(node: ArrowFunction): ConciseBody;
|
||||
function transformAsyncFunctionBody(node: FunctionLikeDeclaration): ConciseBody {
|
||||
resumeLexicalEnvironment();
|
||||
|
||||
const original = getOriginalNode(node, isFunctionLike);
|
||||
const nodeType = original.type;
|
||||
const promiseConstructor = languageVersion < ScriptTarget.ES2015 ? getPromiseConstructor(nodeType) : undefined;
|
||||
@@ -495,8 +491,6 @@ namespace ts {
|
||||
// passed to `__awaiter` is executed inside of the callback to the
|
||||
// promise constructor.
|
||||
|
||||
resumeLexicalEnvironment();
|
||||
|
||||
if (!isArrowFunction) {
|
||||
const statements: Statement[] = [];
|
||||
const statementOffset = addPrologueDirectives(statements, (<Block>node.body).statements, /*ensureUseStrict*/ false, visitor);
|
||||
@@ -541,9 +535,7 @@ namespace ts {
|
||||
const declarations = endLexicalEnvironment();
|
||||
if (some(declarations)) {
|
||||
const block = convertToFunctionBody(expression);
|
||||
const statements = mergeLexicalEnvironment(block.statements, declarations);
|
||||
|
||||
return updateBlock(block, statements);
|
||||
return updateBlock(block, createNodeArray(concatenate(block.statements, declarations), block.statements));
|
||||
}
|
||||
|
||||
return expression;
|
||||
@@ -552,15 +544,13 @@ namespace ts {
|
||||
|
||||
function transformFunctionBodyWorker(body: ConciseBody, start?: number) {
|
||||
if (isBlock(body)) {
|
||||
return updateBlock(
|
||||
body,
|
||||
visitLexicalEnvironment(body.statements, visitor, context, start));
|
||||
return updateBlock(body, visitLexicalEnvironment(body.statements, visitor, context, start));
|
||||
}
|
||||
else {
|
||||
startLexicalEnvironment();
|
||||
const visited = convertToFunctionBody(visitNode(body, visitor, isConciseBody));
|
||||
const statements = mergeLexicalEnvironment(visited.statements, endLexicalEnvironment());
|
||||
return updateBlock(visited, statements);
|
||||
const declarations = endLexicalEnvironment();
|
||||
return updateBlock(visited, createNodeArray(concatenate(visited.statements, declarations), visited.statements));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -679,18 +669,17 @@ namespace ts {
|
||||
* @param emit A callback used to emit the node in the printer.
|
||||
*/
|
||||
function onEmitNode(emitContext: EmitContext, node: Node, emitCallback: (emitContext: EmitContext, node: Node) => void): void {
|
||||
const savedApplicableSubstitutions = applicableSubstitutions;
|
||||
const savedCurrentSuperContainer = currentSuperContainer;
|
||||
// If we need to support substitutions for `super` in an async method,
|
||||
// we should track it here.
|
||||
if (enabledSubstitutions & ES2017SubstitutionFlags.AsyncMethodsWithSuper && isSuperContainer(node)) {
|
||||
const savedCurrentSuperContainer = currentSuperContainer;
|
||||
currentSuperContainer = node;
|
||||
previousOnEmitNode(emitContext, node, emitCallback);
|
||||
currentSuperContainer = savedCurrentSuperContainer;
|
||||
}
|
||||
else {
|
||||
previousOnEmitNode(emitContext, node, emitCallback);
|
||||
}
|
||||
|
||||
previousOnEmitNode(emitContext, node, emitCallback);
|
||||
|
||||
applicableSubstitutions = savedApplicableSubstitutions;
|
||||
currentSuperContainer = savedCurrentSuperContainer;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,418 @@
|
||||
/// <reference path="../factory.ts" />
|
||||
/// <reference path="../visitor.ts" />
|
||||
|
||||
/*@internal*/
|
||||
namespace ts {
|
||||
export function transformESNext(context: TransformationContext) {
|
||||
const {
|
||||
resumeLexicalEnvironment,
|
||||
endLexicalEnvironment
|
||||
} = context;
|
||||
return transformSourceFile;
|
||||
|
||||
function transformSourceFile(node: SourceFile) {
|
||||
if (isDeclarationFile(node)) {
|
||||
return node;
|
||||
}
|
||||
|
||||
const visited = visitEachChild(node, visitor, context);
|
||||
addEmitHelpers(visited, context.readEmitHelpers());
|
||||
return visited;
|
||||
}
|
||||
|
||||
function visitor(node: Node): VisitResult<Node> {
|
||||
return visitorWorker(node, /*noDestructuringValue*/ false);
|
||||
}
|
||||
|
||||
function visitorNoDestructuringValue(node: Node): VisitResult<Node> {
|
||||
return visitorWorker(node, /*noDestructuringValue*/ true);
|
||||
}
|
||||
|
||||
function visitorWorker(node: Node, noDestructuringValue: boolean): VisitResult<Node> {
|
||||
if ((node.transformFlags & TransformFlags.ContainsESNext) === 0) {
|
||||
return node;
|
||||
}
|
||||
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ObjectLiteralExpression:
|
||||
return visitObjectLiteralExpression(node as ObjectLiteralExpression);
|
||||
case SyntaxKind.BinaryExpression:
|
||||
return visitBinaryExpression(node as BinaryExpression, noDestructuringValue);
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
return visitVariableDeclaration(node as VariableDeclaration);
|
||||
case SyntaxKind.ForOfStatement:
|
||||
return visitForOfStatement(node as ForOfStatement);
|
||||
case SyntaxKind.ForStatement:
|
||||
return visitForStatement(node as ForStatement);
|
||||
case SyntaxKind.VoidExpression:
|
||||
return visitVoidExpression(node as VoidExpression);
|
||||
case SyntaxKind.Constructor:
|
||||
return visitConstructorDeclaration(node as ConstructorDeclaration);
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
return visitMethodDeclaration(node as MethodDeclaration);
|
||||
case SyntaxKind.GetAccessor:
|
||||
return visitGetAccessorDeclaration(node as GetAccessorDeclaration);
|
||||
case SyntaxKind.SetAccessor:
|
||||
return visitSetAccessorDeclaration(node as SetAccessorDeclaration);
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
return visitFunctionDeclaration(node as FunctionDeclaration);
|
||||
case SyntaxKind.FunctionExpression:
|
||||
return visitFunctionExpression(node as FunctionExpression);
|
||||
case SyntaxKind.ArrowFunction:
|
||||
return visitArrowFunction(node as ArrowFunction);
|
||||
case SyntaxKind.Parameter:
|
||||
return visitParameter(node as ParameterDeclaration);
|
||||
case SyntaxKind.ExpressionStatement:
|
||||
return visitExpressionStatement(node as ExpressionStatement);
|
||||
case SyntaxKind.ParenthesizedExpression:
|
||||
return visitParenthesizedExpression(node as ParenthesizedExpression, noDestructuringValue);
|
||||
default:
|
||||
return visitEachChild(node, visitor, context);
|
||||
}
|
||||
}
|
||||
|
||||
function chunkObjectLiteralElements(elements: ObjectLiteralElement[]): Expression[] {
|
||||
let chunkObject: (ShorthandPropertyAssignment | PropertyAssignment)[];
|
||||
const objects: Expression[] = [];
|
||||
for (const e of elements) {
|
||||
if (e.kind === SyntaxKind.SpreadAssignment) {
|
||||
if (chunkObject) {
|
||||
objects.push(createObjectLiteral(chunkObject));
|
||||
chunkObject = undefined;
|
||||
}
|
||||
const target = (e as SpreadAssignment).expression;
|
||||
objects.push(visitNode(target, visitor, isExpression));
|
||||
}
|
||||
else {
|
||||
if (!chunkObject) {
|
||||
chunkObject = [];
|
||||
}
|
||||
if (e.kind === SyntaxKind.PropertyAssignment) {
|
||||
const p = e as PropertyAssignment;
|
||||
chunkObject.push(createPropertyAssignment(p.name, visitNode(p.initializer, visitor, isExpression)));
|
||||
}
|
||||
else {
|
||||
chunkObject.push(e as ShorthandPropertyAssignment);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (chunkObject) {
|
||||
objects.push(createObjectLiteral(chunkObject));
|
||||
}
|
||||
|
||||
return objects;
|
||||
}
|
||||
|
||||
function visitObjectLiteralExpression(node: ObjectLiteralExpression): Expression {
|
||||
if (node.transformFlags & TransformFlags.ContainsObjectSpread) {
|
||||
// spread elements emit like so:
|
||||
// non-spread elements are chunked together into object literals, and then all are passed to __assign:
|
||||
// { a, ...o, b } => __assign({a}, o, {b});
|
||||
// If the first element is a spread element, then the first argument to __assign is {}:
|
||||
// { ...o, a, b, ...o2 } => __assign({}, o, {a, b}, o2)
|
||||
const objects = chunkObjectLiteralElements(node.properties);
|
||||
if (objects.length && objects[0].kind !== SyntaxKind.ObjectLiteralExpression) {
|
||||
objects.unshift(createObjectLiteral());
|
||||
}
|
||||
return createAssignHelper(context, objects);
|
||||
}
|
||||
return visitEachChild(node, visitor, context);
|
||||
}
|
||||
|
||||
function visitExpressionStatement(node: ExpressionStatement): ExpressionStatement {
|
||||
return visitEachChild(node, visitorNoDestructuringValue, context);
|
||||
}
|
||||
|
||||
function visitParenthesizedExpression(node: ParenthesizedExpression, noDestructuringValue: boolean): ParenthesizedExpression {
|
||||
return visitEachChild(node, noDestructuringValue ? visitorNoDestructuringValue : visitor, context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a BinaryExpression that contains a destructuring assignment.
|
||||
*
|
||||
* @param node A BinaryExpression node.
|
||||
*/
|
||||
function visitBinaryExpression(node: BinaryExpression, noDestructuringValue: boolean): Expression {
|
||||
if (isDestructuringAssignment(node) && node.left.transformFlags & TransformFlags.ContainsObjectRest) {
|
||||
return flattenDestructuringAssignment(
|
||||
node,
|
||||
visitor,
|
||||
context,
|
||||
FlattenLevel.ObjectRest,
|
||||
!noDestructuringValue
|
||||
);
|
||||
}
|
||||
else if (node.operatorToken.kind === SyntaxKind.CommaToken) {
|
||||
return updateBinary(
|
||||
node,
|
||||
visitNode(node.left, visitorNoDestructuringValue, isExpression),
|
||||
visitNode(node.right, noDestructuringValue ? visitorNoDestructuringValue : visitor, isExpression)
|
||||
);
|
||||
}
|
||||
return visitEachChild(node, visitor, context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a VariableDeclaration node with a binding pattern.
|
||||
*
|
||||
* @param node A VariableDeclaration node.
|
||||
*/
|
||||
function visitVariableDeclaration(node: VariableDeclaration): VisitResult<VariableDeclaration> {
|
||||
// If we are here it is because the name contains a binding pattern with a rest somewhere in it.
|
||||
if (isBindingPattern(node.name) && node.name.transformFlags & TransformFlags.ContainsObjectRest) {
|
||||
return flattenDestructuringBinding(
|
||||
node,
|
||||
visitor,
|
||||
context,
|
||||
FlattenLevel.ObjectRest
|
||||
);
|
||||
}
|
||||
return visitEachChild(node, visitor, context);
|
||||
}
|
||||
|
||||
function visitForStatement(node: ForStatement): VisitResult<Statement> {
|
||||
return updateFor(
|
||||
node,
|
||||
visitNode(node.initializer, visitorNoDestructuringValue, isForInitializer),
|
||||
visitNode(node.condition, visitor, isExpression),
|
||||
visitNode(node.incrementor, visitor, isExpression),
|
||||
visitNode(node.statement, visitor, isStatement)
|
||||
);
|
||||
}
|
||||
|
||||
function visitVoidExpression(node: VoidExpression) {
|
||||
return visitEachChild(node, visitorNoDestructuringValue, context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a ForOfStatement and converts it into a ES2015-compatible ForOfStatement.
|
||||
*
|
||||
* @param node A ForOfStatement.
|
||||
*/
|
||||
function visitForOfStatement(node: ForOfStatement): VisitResult<Statement> {
|
||||
let leadingStatements: Statement[];
|
||||
let temp: Identifier;
|
||||
const initializer = skipParentheses(node.initializer);
|
||||
if (initializer.transformFlags & TransformFlags.ContainsObjectRest) {
|
||||
if (isVariableDeclarationList(initializer)) {
|
||||
temp = createTempVariable(/*recordTempVariable*/ undefined);
|
||||
const firstDeclaration = firstOrUndefined(initializer.declarations);
|
||||
const declarations = flattenDestructuringBinding(
|
||||
firstDeclaration,
|
||||
visitor,
|
||||
context,
|
||||
FlattenLevel.ObjectRest,
|
||||
temp,
|
||||
/*doNotRecordTempVariablesInLine*/ false,
|
||||
/*skipInitializer*/ true,
|
||||
);
|
||||
if (some(declarations)) {
|
||||
const statement = createVariableStatement(
|
||||
/*modifiers*/ undefined,
|
||||
updateVariableDeclarationList(initializer, declarations),
|
||||
/*location*/ initializer
|
||||
);
|
||||
leadingStatements = append(leadingStatements, statement);
|
||||
}
|
||||
}
|
||||
else if (isAssignmentPattern(initializer)) {
|
||||
temp = createTempVariable(/*recordTempVariable*/ undefined);
|
||||
const expression = flattenDestructuringAssignment(
|
||||
aggregateTransformFlags(createAssignment(initializer, temp, /*location*/ node.initializer)),
|
||||
visitor,
|
||||
context,
|
||||
FlattenLevel.ObjectRest
|
||||
);
|
||||
leadingStatements = append(leadingStatements, createStatement(expression, /*location*/ node.initializer));
|
||||
}
|
||||
}
|
||||
if (temp) {
|
||||
const expression = visitNode(node.expression, visitor, isExpression);
|
||||
const statement = visitNode(node.statement, visitor, isStatement);
|
||||
const block = isBlock(statement)
|
||||
? updateBlock(statement, createNodeArray(concatenate(leadingStatements, statement.statements), statement.statements))
|
||||
: createBlock(append(leadingStatements, statement), statement, /*multiLine*/ true);
|
||||
return updateForOf(
|
||||
node,
|
||||
createVariableDeclarationList(
|
||||
[
|
||||
createVariableDeclaration(temp, /*type*/ undefined, /*initializer*/ undefined, node.initializer)
|
||||
],
|
||||
node.initializer,
|
||||
NodeFlags.Let
|
||||
),
|
||||
expression,
|
||||
block
|
||||
);
|
||||
}
|
||||
return visitEachChild(node, visitor, context);
|
||||
}
|
||||
|
||||
function visitParameter(node: ParameterDeclaration): ParameterDeclaration {
|
||||
if (node.transformFlags & TransformFlags.ContainsObjectRest) {
|
||||
// Binding patterns are converted into a generated name and are
|
||||
// evaluated inside the function body.
|
||||
return updateParameter(
|
||||
node,
|
||||
/*decorators*/ undefined,
|
||||
/*modifiers*/ undefined,
|
||||
node.dotDotDotToken,
|
||||
getGeneratedNameForNode(node),
|
||||
/*type*/ undefined,
|
||||
visitNode(node.initializer, visitor, isExpression)
|
||||
);
|
||||
}
|
||||
return visitEachChild(node, visitor, context);
|
||||
}
|
||||
|
||||
function visitConstructorDeclaration(node: ConstructorDeclaration) {
|
||||
return updateConstructor(
|
||||
node,
|
||||
/*decorators*/ undefined,
|
||||
node.modifiers,
|
||||
visitParameterList(node.parameters, visitor, context),
|
||||
transformFunctionBody(node)
|
||||
);
|
||||
}
|
||||
|
||||
function visitGetAccessorDeclaration(node: GetAccessorDeclaration) {
|
||||
return updateGetAccessor(
|
||||
node,
|
||||
/*decorators*/ undefined,
|
||||
node.modifiers,
|
||||
visitNode(node.name, visitor, isPropertyName),
|
||||
visitParameterList(node.parameters, visitor, context),
|
||||
/*type*/ undefined,
|
||||
transformFunctionBody(node)
|
||||
);
|
||||
}
|
||||
|
||||
function visitSetAccessorDeclaration(node: SetAccessorDeclaration) {
|
||||
return updateSetAccessor(
|
||||
node,
|
||||
/*decorators*/ undefined,
|
||||
node.modifiers,
|
||||
visitNode(node.name, visitor, isPropertyName),
|
||||
visitParameterList(node.parameters, visitor, context),
|
||||
transformFunctionBody(node)
|
||||
);
|
||||
}
|
||||
|
||||
function visitMethodDeclaration(node: MethodDeclaration) {
|
||||
return updateMethod(
|
||||
node,
|
||||
/*decorators*/ undefined,
|
||||
node.modifiers,
|
||||
node.asteriskToken,
|
||||
visitNode(node.name, visitor, isPropertyName),
|
||||
/*typeParameters*/ undefined,
|
||||
visitParameterList(node.parameters, visitor, context),
|
||||
/*type*/ undefined,
|
||||
transformFunctionBody(node)
|
||||
);
|
||||
}
|
||||
|
||||
function visitFunctionDeclaration(node: FunctionDeclaration) {
|
||||
return updateFunctionDeclaration(
|
||||
node,
|
||||
/*decorators*/ undefined,
|
||||
node.modifiers,
|
||||
node.asteriskToken,
|
||||
node.name,
|
||||
/*typeParameters*/ undefined,
|
||||
visitParameterList(node.parameters, visitor, context),
|
||||
/*type*/ undefined,
|
||||
transformFunctionBody(node)
|
||||
);
|
||||
}
|
||||
|
||||
function visitArrowFunction(node: ArrowFunction) {
|
||||
return updateArrowFunction(
|
||||
node,
|
||||
node.modifiers,
|
||||
/*typeParameters*/ undefined,
|
||||
visitParameterList(node.parameters, visitor, context),
|
||||
/*type*/ undefined,
|
||||
transformFunctionBody(node)
|
||||
);
|
||||
}
|
||||
|
||||
function visitFunctionExpression(node: FunctionExpression) {
|
||||
return updateFunctionExpression(
|
||||
node,
|
||||
node.modifiers,
|
||||
node.asteriskToken,
|
||||
node.name,
|
||||
/*typeParameters*/ undefined,
|
||||
visitParameterList(node.parameters, visitor, context),
|
||||
/*type*/ undefined,
|
||||
transformFunctionBody(node)
|
||||
);
|
||||
}
|
||||
|
||||
function transformFunctionBody(node: FunctionDeclaration | FunctionExpression | ConstructorDeclaration | MethodDeclaration | AccessorDeclaration): FunctionBody;
|
||||
function transformFunctionBody(node: ArrowFunction): ConciseBody;
|
||||
function transformFunctionBody(node: FunctionLikeDeclaration): ConciseBody {
|
||||
resumeLexicalEnvironment();
|
||||
let leadingStatements: Statement[];
|
||||
for (const parameter of node.parameters) {
|
||||
if (parameter.transformFlags & TransformFlags.ContainsObjectRest) {
|
||||
const temp = getGeneratedNameForNode(parameter);
|
||||
const declarations = flattenDestructuringBinding(
|
||||
parameter,
|
||||
visitor,
|
||||
context,
|
||||
FlattenLevel.ObjectRest,
|
||||
temp,
|
||||
/*doNotRecordTempVariablesInLine*/ false,
|
||||
/*skipInitializer*/ true,
|
||||
);
|
||||
if (some(declarations)) {
|
||||
const statement = createVariableStatement(
|
||||
/*modifiers*/ undefined,
|
||||
createVariableDeclarationList(
|
||||
declarations
|
||||
)
|
||||
);
|
||||
setEmitFlags(statement, EmitFlags.CustomPrologue);
|
||||
leadingStatements = append(leadingStatements, statement);
|
||||
}
|
||||
}
|
||||
}
|
||||
const body = visitNode(node.body, visitor, isConciseBody);
|
||||
const trailingStatements = endLexicalEnvironment();
|
||||
if (some(leadingStatements) || some(trailingStatements)) {
|
||||
const block = convertToFunctionBody(body, /*multiLine*/ true);
|
||||
return updateBlock(block, createNodeArray(concatenate(concatenate(leadingStatements, block.statements), trailingStatements), block.statements));
|
||||
}
|
||||
return body;
|
||||
}
|
||||
}
|
||||
|
||||
const assignHelper: EmitHelper = {
|
||||
name: "typescript:assign",
|
||||
scoped: false,
|
||||
priority: 1,
|
||||
text: `
|
||||
var __assign = (this && this.__assign) || Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
if (typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++)
|
||||
t[p[i]] = s[p[i]];
|
||||
}
|
||||
return t;
|
||||
};`
|
||||
};
|
||||
|
||||
export function createAssignHelper(context: TransformationContext, attributesSegments: Expression[]) {
|
||||
context.requestEmitHelper(assignHelper);
|
||||
return createCall(
|
||||
getHelperName("__assign"),
|
||||
/*typeArguments*/ undefined,
|
||||
attributesSegments
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -227,7 +227,7 @@ namespace ts {
|
||||
|
||||
export function transformGenerators(context: TransformationContext) {
|
||||
const {
|
||||
startLexicalEnvironment,
|
||||
resumeLexicalEnvironment,
|
||||
endLexicalEnvironment,
|
||||
hoistFunctionDeclaration,
|
||||
hoistVariableDeclaration
|
||||
@@ -450,11 +450,11 @@ namespace ts {
|
||||
node = setOriginalNode(
|
||||
createFunctionDeclaration(
|
||||
/*decorators*/ undefined,
|
||||
/*modifiers*/ undefined,
|
||||
node.modifiers,
|
||||
/*asteriskToken*/ undefined,
|
||||
node.name,
|
||||
/*typeParameters*/ undefined,
|
||||
node.parameters,
|
||||
visitParameterList(node.parameters, visitor, context),
|
||||
/*type*/ undefined,
|
||||
transformGeneratorFunctionBody(node.body),
|
||||
/*location*/ node
|
||||
@@ -501,7 +501,7 @@ namespace ts {
|
||||
/*asteriskToken*/ undefined,
|
||||
node.name,
|
||||
/*typeParameters*/ undefined,
|
||||
node.parameters,
|
||||
visitParameterList(node.parameters, visitor, context),
|
||||
/*type*/ undefined,
|
||||
transformGeneratorFunctionBody(node.body),
|
||||
/*location*/ node
|
||||
@@ -579,7 +579,7 @@ namespace ts {
|
||||
state = createTempVariable(/*recordTempVariable*/ undefined);
|
||||
|
||||
// Build the generator
|
||||
startLexicalEnvironment();
|
||||
resumeLexicalEnvironment();
|
||||
|
||||
const statementOffset = addPrologueDirectives(statements, body.statements, /*ensureUseStrict*/ false, visitor);
|
||||
|
||||
@@ -947,7 +947,7 @@ namespace ts {
|
||||
* @param node The node to visit.
|
||||
*/
|
||||
function visitArrayLiteralExpression(node: ArrayLiteralExpression) {
|
||||
return visitElements(node.elements, node.multiLine);
|
||||
return visitElements(node.elements, /*leadingElement*/ undefined, /*location*/ undefined, node.multiLine);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -957,7 +957,7 @@ namespace ts {
|
||||
* @param elements The elements to visit.
|
||||
* @param multiLine Whether array literals created should be emitted on multiple lines.
|
||||
*/
|
||||
function visitElements(elements: NodeArray<Expression>, _multiLine?: boolean) {
|
||||
function visitElements(elements: NodeArray<Expression>, leadingElement?: Expression, location?: TextRange, multiLine?: boolean) {
|
||||
// [source]
|
||||
// ar = [1, yield, 2];
|
||||
//
|
||||
@@ -973,17 +973,21 @@ namespace ts {
|
||||
let temp: Identifier;
|
||||
if (numInitialElements > 0) {
|
||||
temp = declareLocal();
|
||||
const initialElements = visitNodes(elements, visitor, isExpression, 0, numInitialElements);
|
||||
emitAssignment(temp,
|
||||
createArrayLiteral(
|
||||
visitNodes(elements, visitor, isExpression, 0, numInitialElements)
|
||||
leadingElement
|
||||
? [leadingElement, ...initialElements]
|
||||
: initialElements
|
||||
)
|
||||
);
|
||||
leadingElement = undefined;
|
||||
}
|
||||
|
||||
const expressions = reduceLeft(elements, reduceElement, <Expression[]>[], numInitialElements);
|
||||
return temp
|
||||
? createArrayConcat(temp, [createArrayLiteral(expressions)])
|
||||
: createArrayLiteral(expressions);
|
||||
? createArrayConcat(temp, [createArrayLiteral(expressions, /*location*/ undefined, multiLine)])
|
||||
: createArrayLiteral(leadingElement ? [leadingElement, ...expressions] : expressions, location, multiLine);
|
||||
|
||||
function reduceElement(expressions: Expression[], element: Expression) {
|
||||
if (containsYield(element) && expressions.length > 0) {
|
||||
@@ -997,10 +1001,15 @@ namespace ts {
|
||||
hasAssignedTemp
|
||||
? createArrayConcat(
|
||||
temp,
|
||||
[createArrayLiteral(expressions)]
|
||||
[createArrayLiteral(expressions, /*location*/ undefined, multiLine)]
|
||||
)
|
||||
: createArrayLiteral(
|
||||
leadingElement ? [leadingElement, ...expressions] : expressions,
|
||||
/*location*/ undefined,
|
||||
multiLine
|
||||
)
|
||||
: createArrayLiteral(expressions)
|
||||
);
|
||||
leadingElement = undefined;
|
||||
expressions = [];
|
||||
}
|
||||
|
||||
@@ -1136,7 +1145,10 @@ namespace ts {
|
||||
createFunctionApply(
|
||||
cacheExpression(visitNode(target, visitor, isExpression)),
|
||||
thisArg,
|
||||
visitElements(node.arguments)
|
||||
visitElements(
|
||||
node.arguments,
|
||||
/*leadingElement*/ createVoidZero()
|
||||
)
|
||||
),
|
||||
/*typeArguments*/ undefined,
|
||||
[],
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/// <reference path="../factory.ts" />
|
||||
/// <reference path="../visitor.ts" />
|
||||
/// <reference path="./esnext.ts" />
|
||||
|
||||
/*@internal*/
|
||||
namespace ts {
|
||||
@@ -24,12 +25,9 @@ namespace ts {
|
||||
}
|
||||
|
||||
function visitor(node: Node): VisitResult<Node> {
|
||||
if (node.transformFlags & TransformFlags.Jsx) {
|
||||
if (node.transformFlags & TransformFlags.ContainsJsx) {
|
||||
return visitorWorker(node);
|
||||
}
|
||||
else if (node.transformFlags & TransformFlags.ContainsJsx) {
|
||||
return visitEachChild(node, visitor, context);
|
||||
}
|
||||
else {
|
||||
return node;
|
||||
}
|
||||
@@ -47,8 +45,7 @@ namespace ts {
|
||||
return visitJsxExpression(<JsxExpression>node);
|
||||
|
||||
default:
|
||||
Debug.failBadSyntaxKind(node);
|
||||
return undefined;
|
||||
return visitEachChild(node, visitor, context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +109,8 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
const element = createReactCreateElement(
|
||||
const element = createExpressionForJsxElement(
|
||||
context.getEmitResolver().getJsxFactoryEntity(),
|
||||
compilerOptions.reactNamespace,
|
||||
tagName,
|
||||
objectProperties,
|
||||
@@ -529,28 +527,4 @@ namespace ts {
|
||||
"hearts": 0x2665,
|
||||
"diams": 0x2666
|
||||
});
|
||||
|
||||
function createAssignHelper(context: TransformationContext, attributesSegments: Expression[]) {
|
||||
context.requestEmitHelper(assignHelper);
|
||||
return createCall(
|
||||
getHelperName("__assign"),
|
||||
/*typeArguments*/ undefined,
|
||||
attributesSegments
|
||||
);
|
||||
}
|
||||
|
||||
const assignHelper: EmitHelper = {
|
||||
name: "typescript:assign",
|
||||
scoped: false,
|
||||
priority: 1,
|
||||
text: `
|
||||
var __assign = (this && this.__assign) || Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};`
|
||||
};
|
||||
}
|
||||
@@ -20,7 +20,7 @@ namespace ts {
|
||||
|
||||
const {
|
||||
startLexicalEnvironment,
|
||||
endLexicalEnvironment,
|
||||
endLexicalEnvironment
|
||||
} = context;
|
||||
|
||||
const compilerOptions = context.getCompilerOptions();
|
||||
@@ -760,12 +760,13 @@ namespace ts {
|
||||
*/
|
||||
function transformInitializedVariable(node: VariableDeclaration): Expression {
|
||||
if (isBindingPattern(node.name)) {
|
||||
return flattenDestructuringToExpression(
|
||||
context,
|
||||
return flattenDestructuringAssignment(
|
||||
node,
|
||||
/*visitor*/ undefined,
|
||||
context,
|
||||
FlattenLevel.All,
|
||||
/*needsValue*/ false,
|
||||
createExportExpression,
|
||||
/*visitor*/ undefined
|
||||
createExportExpression
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -819,12 +819,14 @@ namespace ts {
|
||||
function transformInitializedVariable(node: VariableDeclaration, isExportedDeclaration: boolean): Expression {
|
||||
const createAssignment = isExportedDeclaration ? createExportedVariableAssignment : createNonExportedVariableAssignment;
|
||||
return isBindingPattern(node.name)
|
||||
? flattenDestructuringToExpression(
|
||||
context,
|
||||
? flattenDestructuringAssignment(
|
||||
node,
|
||||
destructuringVisitor,
|
||||
context,
|
||||
FlattenLevel.All,
|
||||
/*needsValue*/ false,
|
||||
createAssignment,
|
||||
destructuringVisitor)
|
||||
createAssignment
|
||||
)
|
||||
: createAssignment(node.name, visitNode(node.initializer, destructuringVisitor, isExpression));
|
||||
}
|
||||
|
||||
@@ -1475,13 +1477,15 @@ namespace ts {
|
||||
*/
|
||||
function visitDestructuringAssignment(node: DestructuringAssignment): VisitResult<Expression> {
|
||||
if (hasExportedReferenceInDestructuringTarget(node.left)) {
|
||||
return flattenDestructuringToExpression(
|
||||
context,
|
||||
return flattenDestructuringAssignment(
|
||||
node,
|
||||
/*needsValue*/ true,
|
||||
createAssignment,
|
||||
destructuringVisitor);
|
||||
destructuringVisitor,
|
||||
context,
|
||||
FlattenLevel.All,
|
||||
/*needsValue*/ true
|
||||
);
|
||||
}
|
||||
|
||||
return visitEachChild(node, destructuringVisitor, context);
|
||||
}
|
||||
|
||||
@@ -1494,7 +1498,7 @@ namespace ts {
|
||||
if (isAssignmentExpression(node, /*excludeCompoundAssignment*/ true)) {
|
||||
return hasExportedReferenceInDestructuringTarget(node.left);
|
||||
}
|
||||
else if (isSpreadElementExpression(node)) {
|
||||
else if (isSpreadExpression(node)) {
|
||||
return hasExportedReferenceInDestructuringTarget(node.expression);
|
||||
}
|
||||
else if (isObjectLiteralExpression(node)) {
|
||||
|
||||
@@ -330,6 +330,7 @@ namespace ts {
|
||||
case SyntaxKind.ThisType:
|
||||
case SyntaxKind.TypeOperator:
|
||||
case SyntaxKind.IndexedAccessType:
|
||||
case SyntaxKind.MappedType:
|
||||
case SyntaxKind.LiteralType:
|
||||
// TypeScript type nodes are elided.
|
||||
|
||||
@@ -470,9 +471,10 @@ namespace ts {
|
||||
}
|
||||
|
||||
function visitSourceFile(node: SourceFile) {
|
||||
const alwaysStrict = compilerOptions.alwaysStrict && !(isExternalModule(node) && moduleKind === ModuleKind.ES2015);
|
||||
return updateSourceFileNode(
|
||||
node,
|
||||
visitLexicalEnvironment(node.statements, sourceElementVisitor, context, /*start*/ 0, compilerOptions.alwaysStrict));
|
||||
visitLexicalEnvironment(node.statements, sourceElementVisitor, context, /*start*/ 0, alwaysStrict));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -860,7 +862,6 @@ namespace ts {
|
||||
let statements: Statement[] = [];
|
||||
let indexOfFirstStatement = 0;
|
||||
|
||||
// The body of a constructor is a new lexical environment
|
||||
resumeLexicalEnvironment();
|
||||
|
||||
if (constructor) {
|
||||
@@ -1748,6 +1749,7 @@ namespace ts {
|
||||
case SyntaxKind.TypeQuery:
|
||||
case SyntaxKind.TypeOperator:
|
||||
case SyntaxKind.IndexedAccessType:
|
||||
case SyntaxKind.MappedType:
|
||||
case SyntaxKind.TypeLiteral:
|
||||
case SyntaxKind.AnyKeyword:
|
||||
case SyntaxKind.ThisType:
|
||||
@@ -1774,12 +1776,7 @@ namespace ts {
|
||||
const temp = createTempVariable(hoistVariableDeclaration);
|
||||
return createLogicalOr(
|
||||
createLogicalAnd(
|
||||
createStrictEquality(
|
||||
createTypeOf(
|
||||
createAssignment(temp, serialized)
|
||||
),
|
||||
createLiteral("function")
|
||||
),
|
||||
createTypeCheck(createAssignment(temp, serialized), "function"),
|
||||
temp
|
||||
),
|
||||
createIdentifier("Object")
|
||||
@@ -1888,13 +1885,8 @@ namespace ts {
|
||||
*/
|
||||
function getGlobalSymbolNameWithFallback(): Expression {
|
||||
return createConditional(
|
||||
createStrictEquality(
|
||||
createTypeOf(createIdentifier("Symbol")),
|
||||
createLiteral("function")
|
||||
),
|
||||
createToken(SyntaxKind.QuestionToken),
|
||||
createTypeCheck(createIdentifier("Symbol"), "function"),
|
||||
createIdentifier("Symbol"),
|
||||
createToken(SyntaxKind.ColonToken),
|
||||
createIdentifier("Object")
|
||||
);
|
||||
}
|
||||
@@ -2255,12 +2247,14 @@ namespace ts {
|
||||
function transformInitializedVariable(node: VariableDeclaration): Expression {
|
||||
const name = node.name;
|
||||
if (isBindingPattern(name)) {
|
||||
return flattenDestructuringToExpression(
|
||||
context,
|
||||
return flattenDestructuringAssignment(
|
||||
node,
|
||||
visitor,
|
||||
context,
|
||||
FlattenLevel.All,
|
||||
/*needsValue*/ false,
|
||||
createNamespaceExportExpression,
|
||||
visitor);
|
||||
createNamespaceExportExpression
|
||||
);
|
||||
}
|
||||
else {
|
||||
return createAssignment(
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
"visitor.ts",
|
||||
"transformers/ts.ts",
|
||||
"transformers/jsx.ts",
|
||||
"transformers/esnext.ts",
|
||||
"transformers/es2017.ts",
|
||||
"transformers/es2016.ts",
|
||||
"transformers/es2015.ts",
|
||||
|
||||
+197
-84
@@ -219,6 +219,7 @@ namespace ts {
|
||||
ThisType,
|
||||
TypeOperator,
|
||||
IndexedAccessType,
|
||||
MappedType,
|
||||
LiteralType,
|
||||
// Binding patterns
|
||||
ObjectBindingPattern,
|
||||
@@ -246,7 +247,7 @@ namespace ts {
|
||||
ConditionalExpression,
|
||||
TemplateExpression,
|
||||
YieldExpression,
|
||||
SpreadElementExpression,
|
||||
SpreadElement,
|
||||
ClassExpression,
|
||||
OmittedExpression,
|
||||
ExpressionWithTypeArguments,
|
||||
@@ -320,6 +321,7 @@ namespace ts {
|
||||
// Property assignments
|
||||
PropertyAssignment,
|
||||
ShorthandPropertyAssignment,
|
||||
SpreadAssignment,
|
||||
|
||||
// Enum
|
||||
EnumMember,
|
||||
@@ -415,25 +417,20 @@ namespace ts {
|
||||
HasImplicitReturn = 1 << 7, // If function implicitly returns on one of codepaths (initialized by binding)
|
||||
HasExplicitReturn = 1 << 8, // If function has explicit reachable return on one of codepaths (initialized by binding)
|
||||
GlobalAugmentation = 1 << 9, // Set if module declaration is an augmentation for the global scope
|
||||
HasClassExtends = 1 << 10, // If the file has a non-ambient class with an extends clause in ES5 or lower (initialized by binding)
|
||||
HasDecorators = 1 << 11, // If the file has decorators (initialized by binding)
|
||||
HasParamDecorators = 1 << 12, // If the file has parameter decorators (initialized by binding)
|
||||
HasAsyncFunctions = 1 << 13, // If the file has async functions (initialized by binding)
|
||||
HasJsxSpreadAttributes = 1 << 14, // If the file as JSX spread attributes (initialized by binding)
|
||||
DisallowInContext = 1 << 15, // If node was parsed in a context where 'in-expressions' are not allowed
|
||||
YieldContext = 1 << 16, // If node was parsed in the 'yield' context created when parsing a generator
|
||||
DecoratorContext = 1 << 17, // If node was parsed as part of a decorator
|
||||
AwaitContext = 1 << 18, // If node was parsed in the 'await' context created when parsing an async function
|
||||
ThisNodeHasError = 1 << 19, // If the parser encountered an error when parsing the code that created this node
|
||||
JavaScriptFile = 1 << 20, // If node was parsed in a JavaScript
|
||||
ThisNodeOrAnySubNodesHasError = 1 << 21, // If this node or any of its children had an error
|
||||
HasAggregatedChildData = 1 << 22, // If we've computed data from children and cached it in this node
|
||||
DisallowInContext = 1 << 16, // If node was parsed in a context where 'in-expressions' are not allowed
|
||||
YieldContext = 1 << 17, // If node was parsed in the 'yield' context created when parsing a generator
|
||||
DecoratorContext = 1 << 18, // If node was parsed as part of a decorator
|
||||
AwaitContext = 1 << 19, // If node was parsed in the 'await' context created when parsing an async function
|
||||
ThisNodeHasError = 1 << 20, // If the parser encountered an error when parsing the code that created this node
|
||||
JavaScriptFile = 1 << 21, // If node was parsed in a JavaScript
|
||||
ThisNodeOrAnySubNodesHasError = 1 << 22, // If this node or any of its children had an error
|
||||
HasAggregatedChildData = 1 << 23, // If we've computed data from children and cached it in this node
|
||||
|
||||
BlockScoped = Let | Const,
|
||||
|
||||
ReachabilityCheckFlags = HasImplicitReturn | HasExplicitReturn,
|
||||
EmitHelperFlags = HasClassExtends | HasDecorators | HasParamDecorators | HasAsyncFunctions | HasJsxSpreadAttributes,
|
||||
ReachabilityAndEmitFlags = ReachabilityCheckFlags | EmitHelperFlags,
|
||||
ReachabilityAndEmitFlags = ReachabilityCheckFlags | HasAsyncFunctions,
|
||||
|
||||
// Parsing context flags
|
||||
ContextFlags = DisallowInContext | YieldContext | DecoratorContext | AwaitContext | JavaScriptFile,
|
||||
@@ -455,7 +452,6 @@ namespace ts {
|
||||
Async = 1 << 8, // Property/Method/Function
|
||||
Default = 1 << 9, // Function/Class (export default declaration)
|
||||
Const = 1 << 11, // Variable declaration
|
||||
|
||||
HasComputedFlags = 1 << 29, // Modifier flags have been computed
|
||||
|
||||
AccessibilityModifier = Public | Private | Protected,
|
||||
@@ -506,6 +502,7 @@ namespace ts {
|
||||
|
||||
export interface NodeArray<T extends Node> extends Array<T>, TextRange {
|
||||
hasTrailingComma?: boolean;
|
||||
/* @internal */ transformFlags?: TransformFlags;
|
||||
}
|
||||
|
||||
export interface Token<TKind extends SyntaxKind> extends Node {
|
||||
@@ -520,6 +517,7 @@ namespace ts {
|
||||
export type EqualsGreaterThanToken = Token<SyntaxKind.EqualsGreaterThanToken>;
|
||||
export type EndOfFileToken = Token<SyntaxKind.EndOfFileToken>;
|
||||
export type AtToken = Token<SyntaxKind.AtToken>;
|
||||
export type ReadonlyToken = Token<SyntaxKind.ReadonlyKeyword>;
|
||||
export type AwaitKeywordToken = Token<SyntaxKind.AwaitKeyword>;
|
||||
|
||||
export type Modifier
|
||||
@@ -577,9 +575,9 @@ namespace ts {
|
||||
|
||||
export type EntityName = Identifier | QualifiedName;
|
||||
|
||||
export type PropertyName = Identifier | LiteralExpression | ComputedPropertyName;
|
||||
export type PropertyName = Identifier | StringLiteral | NumericLiteral | ComputedPropertyName;
|
||||
|
||||
export type DeclarationName = Identifier | LiteralExpression | ComputedPropertyName | BindingPattern;
|
||||
export type DeclarationName = Identifier | StringLiteral | NumericLiteral | ComputedPropertyName | BindingPattern;
|
||||
|
||||
export interface Declaration extends Node {
|
||||
_declarationBrand: any;
|
||||
@@ -587,7 +585,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
export interface DeclarationStatement extends Declaration, Statement {
|
||||
name?: Identifier | LiteralExpression;
|
||||
name?: Identifier | StringLiteral | NumericLiteral;
|
||||
}
|
||||
|
||||
export interface ComputedPropertyName extends Node {
|
||||
@@ -651,7 +649,7 @@ namespace ts {
|
||||
export interface BindingElement extends Declaration {
|
||||
kind: SyntaxKind.BindingElement;
|
||||
propertyName?: PropertyName; // Binding property name (in object binding pattern)
|
||||
dotDotDotToken?: DotDotDotToken; // Present on rest binding element
|
||||
dotDotDotToken?: DotDotDotToken; // Present on rest element (in object binding pattern)
|
||||
name: BindingName; // Declared binding element name
|
||||
initializer?: Expression; // Optional initializer
|
||||
}
|
||||
@@ -680,6 +678,7 @@ namespace ts {
|
||||
export type ObjectLiteralElementLike
|
||||
= PropertyAssignment
|
||||
| ShorthandPropertyAssignment
|
||||
| SpreadAssignment
|
||||
| MethodDeclaration
|
||||
| AccessorDeclaration
|
||||
;
|
||||
@@ -701,6 +700,11 @@ namespace ts {
|
||||
objectAssignmentInitializer?: Expression;
|
||||
}
|
||||
|
||||
export interface SpreadAssignment extends ObjectLiteralElement {
|
||||
kind: SyntaxKind.SpreadAssignment;
|
||||
expression: Expression;
|
||||
}
|
||||
|
||||
// SyntaxKind.VariableDeclaration
|
||||
// SyntaxKind.Parameter
|
||||
// SyntaxKind.BindingElement
|
||||
@@ -722,23 +726,20 @@ namespace ts {
|
||||
name: PropertyName;
|
||||
}
|
||||
|
||||
export interface BindingPattern extends Node {
|
||||
kind: SyntaxKind.ObjectBindingPattern | SyntaxKind.ArrayBindingPattern;
|
||||
elements: NodeArray<BindingElement | ArrayBindingElement>;
|
||||
}
|
||||
|
||||
export interface ObjectBindingPattern extends BindingPattern {
|
||||
export interface ObjectBindingPattern extends Node {
|
||||
kind: SyntaxKind.ObjectBindingPattern;
|
||||
elements: NodeArray<BindingElement>;
|
||||
}
|
||||
|
||||
export type ArrayBindingElement = BindingElement | OmittedExpression;
|
||||
|
||||
export interface ArrayBindingPattern extends BindingPattern {
|
||||
export interface ArrayBindingPattern extends Node {
|
||||
kind: SyntaxKind.ArrayBindingPattern;
|
||||
elements: NodeArray<ArrayBindingElement>;
|
||||
}
|
||||
|
||||
export type BindingPattern = ObjectBindingPattern | ArrayBindingPattern;
|
||||
|
||||
export type ArrayBindingElement = BindingElement | OmittedExpression;
|
||||
|
||||
/**
|
||||
* Several node kinds share function-like features such as a signature,
|
||||
* a name, and a body. These nodes should extend FunctionLikeDeclaration.
|
||||
@@ -905,6 +906,14 @@ namespace ts {
|
||||
indexType: TypeNode;
|
||||
}
|
||||
|
||||
export interface MappedTypeNode extends TypeNode, Declaration {
|
||||
kind: SyntaxKind.MappedType;
|
||||
readonlyToken?: ReadonlyToken;
|
||||
typeParameter: TypeParameterDeclaration;
|
||||
questionToken?: QuestionToken;
|
||||
type?: TypeNode;
|
||||
}
|
||||
|
||||
export interface LiteralTypeNode extends TypeNode {
|
||||
kind: SyntaxKind.LiteralType;
|
||||
literal: Expression;
|
||||
@@ -912,7 +921,7 @@ namespace ts {
|
||||
|
||||
export interface StringLiteral extends LiteralExpression {
|
||||
kind: SyntaxKind.StringLiteral;
|
||||
/* @internal */ textSourceNode?: Identifier | StringLiteral; // Allows a StringLiteral to get its text from another node (used by transforms).
|
||||
/* @internal */ textSourceNode?: Identifier | StringLiteral | NumericLiteral; // Allows a StringLiteral to get its text from another node (used by transforms).
|
||||
}
|
||||
|
||||
// Note: 'brands' in our syntax nodes serve to give us a small amount of nominal typing.
|
||||
@@ -1177,20 +1186,64 @@ namespace ts {
|
||||
right: Expression;
|
||||
}
|
||||
|
||||
export interface AssignmentExpression<TKind extends AssignmentOperator> extends BinaryExpression {
|
||||
export type AssignmentOperatorToken = Token<AssignmentOperator>;
|
||||
|
||||
export interface AssignmentExpression<TOperator extends AssignmentOperatorToken> extends BinaryExpression {
|
||||
left: LeftHandSideExpression;
|
||||
operatorToken: Token<TKind>;
|
||||
operatorToken: TOperator;
|
||||
}
|
||||
|
||||
export interface ObjectDestructuringAssignment extends AssignmentExpression<SyntaxKind.EqualsToken> {
|
||||
export interface ObjectDestructuringAssignment extends AssignmentExpression<EqualsToken> {
|
||||
left: ObjectLiteralExpression;
|
||||
}
|
||||
|
||||
export interface ArrayDestructuringAssignment extends AssignmentExpression<SyntaxKind.EqualsToken> {
|
||||
export interface ArrayDestructuringAssignment extends AssignmentExpression<EqualsToken> {
|
||||
left: ArrayLiteralExpression;
|
||||
}
|
||||
|
||||
export type DestructuringAssignment = ObjectDestructuringAssignment | ArrayDestructuringAssignment;
|
||||
export type DestructuringAssignment
|
||||
= ObjectDestructuringAssignment
|
||||
| ArrayDestructuringAssignment
|
||||
;
|
||||
|
||||
export type BindingOrAssignmentElement
|
||||
= VariableDeclaration
|
||||
| ParameterDeclaration
|
||||
| BindingElement
|
||||
| PropertyAssignment // AssignmentProperty
|
||||
| ShorthandPropertyAssignment // AssignmentProperty
|
||||
| SpreadAssignment // AssignmentRestProperty
|
||||
| OmittedExpression // Elision
|
||||
| SpreadElement // AssignmentRestElement
|
||||
| ArrayLiteralExpression // ArrayAssignmentPattern
|
||||
| ObjectLiteralExpression // ObjectAssignmentPattern
|
||||
| AssignmentExpression<EqualsToken> // AssignmentElement
|
||||
| Identifier // DestructuringAssignmentTarget
|
||||
| PropertyAccessExpression // DestructuringAssignmentTarget
|
||||
| ElementAccessExpression // DestructuringAssignmentTarget
|
||||
;
|
||||
|
||||
export type BindingOrAssignmentElementRestIndicator
|
||||
= DotDotDotToken // from BindingElement
|
||||
| SpreadElement // AssignmentRestElement
|
||||
| SpreadAssignment // AssignmentRestProperty
|
||||
;
|
||||
|
||||
export type BindingOrAssignmentElementTarget = BindingOrAssignmentPattern | Expression;
|
||||
|
||||
export type ObjectBindingOrAssignmentPattern
|
||||
= ObjectBindingPattern
|
||||
| ObjectLiteralExpression // ObjectAssignmentPattern
|
||||
;
|
||||
|
||||
export type ArrayBindingOrAssignmentPattern
|
||||
= ArrayBindingPattern
|
||||
| ArrayLiteralExpression // ArrayAssignmentPattern
|
||||
;
|
||||
|
||||
export type AssignmentPattern = ObjectLiteralExpression | ArrayLiteralExpression;
|
||||
|
||||
export type BindingOrAssignmentPattern = ObjectBindingOrAssignmentPattern | ArrayBindingOrAssignmentPattern;
|
||||
|
||||
export interface ConditionalExpression extends Expression {
|
||||
kind: SyntaxKind.ConditionalExpression;
|
||||
@@ -1287,8 +1340,8 @@ namespace ts {
|
||||
multiLine?: boolean;
|
||||
}
|
||||
|
||||
export interface SpreadElementExpression extends Expression {
|
||||
kind: SyntaxKind.SpreadElementExpression;
|
||||
export interface SpreadElement extends Expression {
|
||||
kind: SyntaxKind.SpreadElement;
|
||||
expression: Expression;
|
||||
}
|
||||
|
||||
@@ -1711,7 +1764,7 @@ namespace ts {
|
||||
|
||||
export interface ModuleDeclaration extends DeclarationStatement {
|
||||
kind: SyntaxKind.ModuleDeclaration;
|
||||
name: Identifier | LiteralExpression;
|
||||
name: Identifier | StringLiteral;
|
||||
body?: ModuleBlock | NamespaceDeclaration | JSDocNamespaceDeclaration | Identifier;
|
||||
}
|
||||
|
||||
@@ -1917,7 +1970,7 @@ namespace ts {
|
||||
|
||||
export interface JSDocRecordMember extends PropertySignature {
|
||||
kind: SyntaxKind.JSDocRecordMember;
|
||||
name: Identifier | LiteralExpression;
|
||||
name: Identifier | StringLiteral | NumericLiteral;
|
||||
type?: JSDocType;
|
||||
}
|
||||
|
||||
@@ -2403,6 +2456,12 @@ namespace ts {
|
||||
CannotBeNamed
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export const enum SyntheticSymbolKind {
|
||||
UnionOrIntersection,
|
||||
Spread
|
||||
}
|
||||
|
||||
export const enum TypePredicateKind {
|
||||
This,
|
||||
Identifier
|
||||
@@ -2495,6 +2554,7 @@ namespace ts {
|
||||
getTypeReferenceDirectivesForSymbol(symbol: Symbol, meaning?: SymbolFlags): string[];
|
||||
isLiteralConstDeclaration(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration): boolean;
|
||||
writeLiteralConstValue(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration, writer: SymbolWriter): void;
|
||||
getJsxFactoryEntity(): EntityName;
|
||||
}
|
||||
|
||||
export const enum SymbolFlags {
|
||||
@@ -2510,7 +2570,7 @@ namespace ts {
|
||||
RegularEnum = 0x00000100, // Enum
|
||||
ValueModule = 0x00000200, // Instantiated module
|
||||
NamespaceModule = 0x00000400, // Uninstantiated module
|
||||
TypeLiteral = 0x00000800, // Type Literal
|
||||
TypeLiteral = 0x00000800, // Type Literal or mapped type
|
||||
ObjectLiteral = 0x00001000, // Object Literal
|
||||
Method = 0x00002000, // Method
|
||||
Constructor = 0x00004000, // Constructor
|
||||
@@ -2614,7 +2674,9 @@ namespace ts {
|
||||
instantiations?: Map<Type>; // Instantiations of generic type alias (undefined if non-generic)
|
||||
mapper?: TypeMapper; // Type mapper for instantiation alias
|
||||
referenced?: boolean; // True if alias symbol has been referenced as a value
|
||||
containingType?: UnionOrIntersectionType; // Containing union or intersection type for synthetic property
|
||||
containingType?: UnionOrIntersectionType; // Containing union or intersection type for synthetic property
|
||||
leftSpread?: Symbol; // Left source for synthetic spread property
|
||||
rightSpread?: Symbol; // Right source for synthetic spread property
|
||||
hasNonUniformType?: boolean; // True if constituents have non-uniform types
|
||||
isPartial?: boolean; // True if syntheric property of union type occurs in some but not all constituents
|
||||
isDiscriminantProperty?: boolean; // True if discriminant synthetic property
|
||||
@@ -2675,6 +2737,7 @@ namespace ts {
|
||||
resolvedSignature?: Signature; // Cached signature of signature node or call expression
|
||||
resolvedSymbol?: Symbol; // Cached name resolution result
|
||||
resolvedIndexInfo?: IndexInfo; // Cached indexing info resolution result
|
||||
maybeTypePredicate?: boolean; // Cached check whether call expression might reference a type predicate
|
||||
enumMemberValue?: number; // Constant value of enum member
|
||||
isVisible?: boolean; // Is this node visible
|
||||
hasReportedStatementInAmbientContext?: boolean; // Cache boolean if we report statements in ambient context
|
||||
@@ -2786,10 +2849,11 @@ namespace ts {
|
||||
Reference = 1 << 2, // Generic type reference
|
||||
Tuple = 1 << 3, // Synthesized generic tuple type
|
||||
Anonymous = 1 << 4, // Anonymous
|
||||
Instantiated = 1 << 5, // Instantiated anonymous type
|
||||
ObjectLiteral = 1 << 6, // Originates in an object literal
|
||||
EvolvingArray = 1 << 7, // Evolving array type
|
||||
ObjectLiteralPatternWithComputedProperties = 1 << 8, // Object literal pattern with computed properties
|
||||
Mapped = 1 << 5, // Mapped
|
||||
Instantiated = 1 << 6, // Instantiated anonymous or mapped type
|
||||
ObjectLiteral = 1 << 7, // Originates in an object literal
|
||||
EvolvingArray = 1 << 8, // Evolving array type
|
||||
ObjectLiteralPatternWithComputedProperties = 1 << 9, // Object literal pattern with computed properties
|
||||
ClassOrInterface = Class | Interface
|
||||
}
|
||||
|
||||
@@ -2858,6 +2922,15 @@ namespace ts {
|
||||
mapper?: TypeMapper; // Instantiation mapper
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export interface MappedType extends ObjectType {
|
||||
declaration: MappedTypeNode;
|
||||
typeParameter?: TypeParameter;
|
||||
constraintType?: Type;
|
||||
templateType?: Type;
|
||||
mapper?: TypeMapper; // Instantiation mapper
|
||||
}
|
||||
|
||||
export interface EvolvingArrayType extends ObjectType {
|
||||
elementType: Type; // Element expressions of evolving array type
|
||||
finalArrayType?: Type; // Final array type of evolving array type
|
||||
@@ -3090,7 +3163,7 @@ namespace ts {
|
||||
moduleResolution?: ModuleResolutionKind;
|
||||
newLine?: NewLineKind;
|
||||
noEmit?: boolean;
|
||||
/*@internal*/noEmitOverwritenFiles?: boolean;
|
||||
/*@internal*/noEmitForJsFiles?: boolean;
|
||||
noEmitHelpers?: boolean;
|
||||
noEmitOnError?: boolean;
|
||||
noErrorTruncation?: boolean;
|
||||
@@ -3111,6 +3184,7 @@ namespace ts {
|
||||
project?: string;
|
||||
/* @internal */ pretty?: DiagnosticStyle;
|
||||
reactNamespace?: string;
|
||||
jsxFactory?: string;
|
||||
removeComments?: boolean;
|
||||
rootDir?: string;
|
||||
rootDirs?: string[];
|
||||
@@ -3193,7 +3267,8 @@ namespace ts {
|
||||
ES2015 = 2,
|
||||
ES2016 = 3,
|
||||
ES2017 = 4,
|
||||
Latest = ES2017,
|
||||
ESNext = 5,
|
||||
Latest = ESNext,
|
||||
}
|
||||
|
||||
export const enum LanguageVariant {
|
||||
@@ -3506,43 +3581,45 @@ namespace ts {
|
||||
// - Flags used to indicate that a node or subtree contains syntax that requires transformation.
|
||||
TypeScript = 1 << 0,
|
||||
ContainsTypeScript = 1 << 1,
|
||||
Jsx = 1 << 2,
|
||||
ContainsJsx = 1 << 3,
|
||||
ES2017 = 1 << 4,
|
||||
ContainsES2017 = 1 << 5,
|
||||
ES2016 = 1 << 6,
|
||||
ContainsES2016 = 1 << 7,
|
||||
ES2015 = 1 << 8,
|
||||
ContainsES2015 = 1 << 9,
|
||||
Generator = 1 << 10,
|
||||
ContainsGenerator = 1 << 11,
|
||||
DestructuringAssignment = 1 << 12,
|
||||
ContainsDestructuringAssignment = 1 << 13,
|
||||
ContainsJsx = 1 << 2,
|
||||
ContainsESNext = 1 << 3,
|
||||
ContainsES2017 = 1 << 4,
|
||||
ContainsES2016 = 1 << 5,
|
||||
ES2015 = 1 << 6,
|
||||
ContainsES2015 = 1 << 7,
|
||||
Generator = 1 << 8,
|
||||
ContainsGenerator = 1 << 9,
|
||||
DestructuringAssignment = 1 << 10,
|
||||
ContainsDestructuringAssignment = 1 << 11,
|
||||
|
||||
// Markers
|
||||
// - Flags used to indicate that a subtree contains a specific transformation.
|
||||
ContainsDecorators = 1 << 14,
|
||||
ContainsPropertyInitializer = 1 << 15,
|
||||
ContainsLexicalThis = 1 << 16,
|
||||
ContainsCapturedLexicalThis = 1 << 17,
|
||||
ContainsLexicalThisInComputedPropertyName = 1 << 18,
|
||||
ContainsDefaultValueAssignments = 1 << 19,
|
||||
ContainsParameterPropertyAssignments = 1 << 20,
|
||||
ContainsSpreadElementExpression = 1 << 21,
|
||||
ContainsComputedPropertyName = 1 << 22,
|
||||
ContainsBlockScopedBinding = 1 << 23,
|
||||
ContainsBindingPattern = 1 << 24,
|
||||
ContainsYield = 1 << 25,
|
||||
ContainsHoistedDeclarationOrCompletion = 1 << 26,
|
||||
ContainsDecorators = 1 << 12,
|
||||
ContainsPropertyInitializer = 1 << 13,
|
||||
ContainsLexicalThis = 1 << 14,
|
||||
ContainsCapturedLexicalThis = 1 << 15,
|
||||
ContainsLexicalThisInComputedPropertyName = 1 << 16,
|
||||
ContainsDefaultValueAssignments = 1 << 17,
|
||||
ContainsParameterPropertyAssignments = 1 << 18,
|
||||
ContainsSpread = 1 << 19,
|
||||
ContainsObjectSpread = 1 << 20,
|
||||
ContainsRest = ContainsSpread,
|
||||
ContainsObjectRest = ContainsObjectSpread,
|
||||
ContainsComputedPropertyName = 1 << 21,
|
||||
ContainsBlockScopedBinding = 1 << 22,
|
||||
ContainsBindingPattern = 1 << 23,
|
||||
ContainsYield = 1 << 24,
|
||||
ContainsHoistedDeclarationOrCompletion = 1 << 25,
|
||||
|
||||
HasComputedFlags = 1 << 29, // Transform flags have been computed.
|
||||
|
||||
// Assertions
|
||||
// - Bitmasks that are used to assert facts about the syntax of a node and its subtree.
|
||||
AssertTypeScript = TypeScript | ContainsTypeScript,
|
||||
AssertJsx = Jsx | ContainsJsx,
|
||||
AssertES2017 = ES2017 | ContainsES2017,
|
||||
AssertES2016 = ES2016 | ContainsES2016,
|
||||
AssertJsx = ContainsJsx,
|
||||
AssertESNext = ContainsESNext,
|
||||
AssertES2017 = ContainsES2017,
|
||||
AssertES2016 = ContainsES2016,
|
||||
AssertES2015 = ES2015 | ContainsES2015,
|
||||
AssertGenerator = Generator | ContainsGenerator,
|
||||
AssertDestructuringAssignment = DestructuringAssignment | ContainsDestructuringAssignment,
|
||||
@@ -3550,18 +3627,20 @@ namespace ts {
|
||||
// Scope Exclusions
|
||||
// - Bitmasks that exclude flags from propagating out of a specific context
|
||||
// into the subtree flags of their container.
|
||||
NodeExcludes = TypeScript | Jsx | ES2017 | ES2016 | ES2015 | DestructuringAssignment | Generator | HasComputedFlags,
|
||||
ArrowFunctionExcludes = NodeExcludes | ContainsDecorators | ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsParameterPropertyAssignments | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclarationOrCompletion,
|
||||
FunctionExcludes = NodeExcludes | ContainsDecorators | ContainsDefaultValueAssignments | ContainsCapturedLexicalThis | ContainsLexicalThis | ContainsParameterPropertyAssignments | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclarationOrCompletion,
|
||||
ConstructorExcludes = NodeExcludes | ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclarationOrCompletion,
|
||||
MethodOrAccessorExcludes = NodeExcludes | ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclarationOrCompletion,
|
||||
NodeExcludes = TypeScript | ES2015 | DestructuringAssignment | Generator | HasComputedFlags,
|
||||
ArrowFunctionExcludes = NodeExcludes | ContainsDecorators | ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsParameterPropertyAssignments | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclarationOrCompletion | ContainsBindingPattern | ContainsObjectRest,
|
||||
FunctionExcludes = NodeExcludes | ContainsDecorators | ContainsDefaultValueAssignments | ContainsCapturedLexicalThis | ContainsLexicalThis | ContainsParameterPropertyAssignments | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclarationOrCompletion | ContainsBindingPattern | ContainsObjectRest,
|
||||
ConstructorExcludes = NodeExcludes | ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclarationOrCompletion | ContainsBindingPattern | ContainsObjectRest,
|
||||
MethodOrAccessorExcludes = NodeExcludes | ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclarationOrCompletion | ContainsBindingPattern | ContainsObjectRest,
|
||||
ClassExcludes = NodeExcludes | ContainsDecorators | ContainsPropertyInitializer | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsComputedPropertyName | ContainsParameterPropertyAssignments | ContainsLexicalThisInComputedPropertyName,
|
||||
ModuleExcludes = NodeExcludes | ContainsDecorators | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding | ContainsHoistedDeclarationOrCompletion,
|
||||
TypeExcludes = ~ContainsTypeScript,
|
||||
ObjectLiteralExcludes = NodeExcludes | ContainsDecorators | ContainsComputedPropertyName | ContainsLexicalThisInComputedPropertyName,
|
||||
ArrayLiteralOrCallOrNewExcludes = NodeExcludes | ContainsSpreadElementExpression,
|
||||
VariableDeclarationListExcludes = NodeExcludes | ContainsBindingPattern,
|
||||
ParameterExcludes = NodeExcludes | ContainsBindingPattern,
|
||||
ObjectLiteralExcludes = NodeExcludes | ContainsDecorators | ContainsComputedPropertyName | ContainsLexicalThisInComputedPropertyName | ContainsObjectSpread,
|
||||
ArrayLiteralOrCallOrNewExcludes = NodeExcludes | ContainsSpread,
|
||||
VariableDeclarationListExcludes = NodeExcludes | ContainsBindingPattern | ContainsObjectRest,
|
||||
ParameterExcludes = NodeExcludes,
|
||||
CatchClauseExcludes = NodeExcludes | ContainsObjectRest,
|
||||
BindingPatternExcludes = NodeExcludes | ContainsRest,
|
||||
|
||||
// Masks
|
||||
// - Additional bitmasks
|
||||
@@ -3618,6 +3697,40 @@ namespace ts {
|
||||
readonly priority?: number; // Helpers with a higher priority are emitted earlier than other helpers on the node.
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export const enum ExternalEmitHelpers {
|
||||
Extends = 1 << 0, // __extends (used by the ES2015 class transformation)
|
||||
Assign = 1 << 1, // __assign (used by Jsx and ESNext object spread transformations)
|
||||
Rest = 1 << 2, // __rest (used by ESNext object rest transformation)
|
||||
Decorate = 1 << 3, // __decorate (used by TypeScript decorators transformation)
|
||||
Metadata = 1 << 4, // __metadata (used by TypeScript decorators transformation)
|
||||
Param = 1 << 5, // __param (used by TypeScript decorators transformation)
|
||||
Awaiter = 1 << 6, // __awaiter (used by ES2017 async functions transformation)
|
||||
Generator = 1 << 7, // __generator (used by ES2015 generator transformation)
|
||||
|
||||
Values = 1 << 8, // __values (used by ES2015 for..of and yield* transformations)
|
||||
Step = 1 << 9, // __step (used by ES2015 for..of transformation)
|
||||
Close = 1 << 10, // __close (used by ES2015 for..of transformation)
|
||||
Read = 1 << 11, // __read (used by ES2015 iterator destructuring transformation)
|
||||
Spread = 1 << 12, // __spread (used by ES2015 array spread and argument list spread transformations)
|
||||
AsyncGenerator = 1 << 13, // __asyncGenerator (used by ES2017 async generator transformation)
|
||||
AsyncValues = 1 << 14, // __asyncValues (used by ES2017 for..await..of transformation)
|
||||
AsyncStep = 1 << 15, // __asyncStep (used by ES2017 for..await..of transformation)
|
||||
AsyncDelegator = 1 << 16, // __asyncDelegator (used by ES2017 async generator yield* transformation)
|
||||
|
||||
// Helpers included by ES2015 for..of
|
||||
ForOfIncludes = Values | Step | Close,
|
||||
|
||||
// Helpers included by ES2017 for..await..of
|
||||
ForAwaitOfIncludes = AsyncValues | AsyncStep | Close,
|
||||
|
||||
// Helpers included by ES2015 spread
|
||||
SpreadIncludes = Read | Spread,
|
||||
|
||||
FirstEmitHelper = Extends,
|
||||
LastEmitHelper = Spread
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export const enum EmitContext {
|
||||
SourceFile, // Emitting a SourceFile
|
||||
|
||||
+148
-44
@@ -177,7 +177,7 @@ namespace ts {
|
||||
export function nodePosToString(node: Node): string {
|
||||
const file = getSourceFileOfNode(node);
|
||||
const loc = getLineAndCharacterOfPosition(file, node.pos);
|
||||
return `${ file.fileName }(${ loc.line + 1 },${ loc.character + 1 })`;
|
||||
return `${file.fileName}(${loc.line + 1},${loc.character + 1})`;
|
||||
}
|
||||
|
||||
export function getStartPosOfNode(node: Node): number {
|
||||
@@ -424,7 +424,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
export function isBlockScope(node: Node, parentNode: Node) {
|
||||
switch (node.kind) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.SourceFile:
|
||||
case SyntaxKind.CaseBlock:
|
||||
case SyntaxKind.CatchClause:
|
||||
@@ -470,6 +470,22 @@ namespace ts {
|
||||
return getFullWidth(name) === 0 ? "(Missing)" : getTextOfNode(name);
|
||||
}
|
||||
|
||||
export function getTextOfPropertyName(name: PropertyName): string {
|
||||
switch (name.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
return (<Identifier>name).text;
|
||||
case SyntaxKind.StringLiteral:
|
||||
case SyntaxKind.NumericLiteral:
|
||||
return (<LiteralExpression>name).text;
|
||||
case SyntaxKind.ComputedPropertyName:
|
||||
if (isStringOrNumericLiteral((<ComputedPropertyName>name).expression)) {
|
||||
return (<LiteralExpression>(<ComputedPropertyName>name).expression).text;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function entityNameToString(name: EntityNameOrEntityNameExpression): string {
|
||||
switch (name.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
@@ -483,6 +499,10 @@ namespace ts {
|
||||
|
||||
export function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number): Diagnostic {
|
||||
const sourceFile = getSourceFileOfNode(node);
|
||||
return createDiagnosticForNodeInSourceFile(sourceFile, node, message, arg0, arg1, arg2);
|
||||
}
|
||||
|
||||
export function createDiagnosticForNodeInSourceFile(sourceFile: SourceFile, node: Node, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number): Diagnostic {
|
||||
const span = getErrorSpanForNode(sourceFile, node);
|
||||
return createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2);
|
||||
}
|
||||
@@ -610,9 +630,9 @@ namespace ts {
|
||||
|
||||
export function getJsDocCommentsFromText(node: Node, text: string) {
|
||||
const commentRanges = (node.kind === SyntaxKind.Parameter ||
|
||||
node.kind === SyntaxKind.TypeParameter ||
|
||||
node.kind === SyntaxKind.FunctionExpression ||
|
||||
node.kind === SyntaxKind.ArrowFunction) ?
|
||||
node.kind === SyntaxKind.TypeParameter ||
|
||||
node.kind === SyntaxKind.FunctionExpression ||
|
||||
node.kind === SyntaxKind.ArrowFunction) ?
|
||||
concatenate(getTrailingCommentRanges(text, node.pos), getLeadingCommentRanges(text, node.pos)) :
|
||||
getLeadingCommentRangesOfNodeFromText(node, text);
|
||||
return filter(commentRanges, isJsDocComment);
|
||||
@@ -890,7 +910,7 @@ namespace ts {
|
||||
export function isObjectLiteralOrClassExpressionMethod(node: Node): node is MethodDeclaration {
|
||||
return node.kind === SyntaxKind.MethodDeclaration &&
|
||||
(node.parent.kind === SyntaxKind.ObjectLiteralExpression ||
|
||||
node.parent.kind === SyntaxKind.ClassExpression);
|
||||
node.parent.kind === SyntaxKind.ClassExpression);
|
||||
}
|
||||
|
||||
export function isIdentifierTypePredicate(predicate: TypePredicate): predicate is IdentifierTypePredicate {
|
||||
@@ -1112,8 +1132,8 @@ namespace ts {
|
||||
// if the parameter's parent has a body and its grandparent is a class declaration, this is a valid target;
|
||||
return (<FunctionLikeDeclaration>node.parent).body !== undefined
|
||||
&& (node.parent.kind === SyntaxKind.Constructor
|
||||
|| node.parent.kind === SyntaxKind.MethodDeclaration
|
||||
|| node.parent.kind === SyntaxKind.SetAccessor)
|
||||
|| node.parent.kind === SyntaxKind.MethodDeclaration
|
||||
|| node.parent.kind === SyntaxKind.SetAccessor)
|
||||
&& node.parent.parent.kind === SyntaxKind.ClassDeclaration;
|
||||
}
|
||||
|
||||
@@ -1178,7 +1198,7 @@ namespace ts {
|
||||
case SyntaxKind.PostfixUnaryExpression:
|
||||
case SyntaxKind.BinaryExpression:
|
||||
case SyntaxKind.ConditionalExpression:
|
||||
case SyntaxKind.SpreadElementExpression:
|
||||
case SyntaxKind.SpreadElement:
|
||||
case SyntaxKind.TemplateExpression:
|
||||
case SyntaxKind.NoSubstitutionTemplateLiteral:
|
||||
case SyntaxKind.OmittedExpression:
|
||||
@@ -1241,6 +1261,7 @@ namespace ts {
|
||||
case SyntaxKind.Decorator:
|
||||
case SyntaxKind.JsxExpression:
|
||||
case SyntaxKind.JsxSpreadAttribute:
|
||||
case SyntaxKind.SpreadAssignment:
|
||||
return true;
|
||||
case SyntaxKind.ExpressionWithTypeArguments:
|
||||
return (<ExpressionWithTypeArguments>parent).expression === node && isExpressionWithTypeArgumentsInClassExtendsClause(parent);
|
||||
@@ -1460,7 +1481,7 @@ namespace ts {
|
||||
}, tags => tags);
|
||||
}
|
||||
|
||||
function getJSDocs<T>(node: Node, checkParentVariableStatement: boolean, getDocs: (docs: JSDoc[]) => T[], getTags: (tags: JSDocTag[]) => T[]): T[] {
|
||||
function getJSDocs<T>(node: Node, checkParentVariableStatement: boolean, getDocs: (docs: JSDoc[]) => T[], getTags: (tags: JSDocTag[]) => T[]): T[] {
|
||||
// TODO: Get rid of getJsDocComments and friends (note the lowercase 's' in Js)
|
||||
// TODO: A lot of this work should be cached, maybe. I guess it's only used in services right now...
|
||||
let result: T[] = undefined;
|
||||
@@ -1481,8 +1502,8 @@ namespace ts {
|
||||
|
||||
const variableStatementNode =
|
||||
isInitializerOfVariableDeclarationInStatement ? node.parent.parent.parent :
|
||||
isVariableOfVariableDeclarationStatement ? node.parent.parent :
|
||||
undefined;
|
||||
isVariableOfVariableDeclarationStatement ? node.parent.parent :
|
||||
undefined;
|
||||
if (variableStatementNode) {
|
||||
result = append(result, getJSDocs(variableStatementNode, checkParentVariableStatement, getDocs, getTags));
|
||||
}
|
||||
@@ -1640,14 +1661,14 @@ namespace ts {
|
||||
return (<ForInStatement | ForOfStatement>parent).initializer === node ? AssignmentKind.Definite : AssignmentKind.None;
|
||||
case SyntaxKind.ParenthesizedExpression:
|
||||
case SyntaxKind.ArrayLiteralExpression:
|
||||
case SyntaxKind.SpreadElementExpression:
|
||||
case SyntaxKind.SpreadElement:
|
||||
node = parent;
|
||||
break;
|
||||
case SyntaxKind.ShorthandPropertyAssignment:
|
||||
if ((<ShorthandPropertyAssignment>parent).name !== node) {
|
||||
return AssignmentKind.None;
|
||||
}
|
||||
// Fall through
|
||||
// Fall through
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
node = parent.parent;
|
||||
break;
|
||||
@@ -1901,8 +1922,10 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isStringOrNumericLiteral(kind: SyntaxKind): boolean {
|
||||
return kind === SyntaxKind.StringLiteral || kind === SyntaxKind.NumericLiteral;
|
||||
export function isStringOrNumericLiteral(node: Node): node is StringLiteral | NumericLiteral {
|
||||
const kind = node.kind;
|
||||
return kind === SyntaxKind.StringLiteral
|
||||
|| kind === SyntaxKind.NumericLiteral;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1918,7 +1941,7 @@ namespace ts {
|
||||
|
||||
export function isDynamicName(name: DeclarationName): boolean {
|
||||
return name.kind === SyntaxKind.ComputedPropertyName &&
|
||||
!isStringOrNumericLiteral((<ComputedPropertyName>name).expression.kind) &&
|
||||
!isStringOrNumericLiteral((<ComputedPropertyName>name).expression) &&
|
||||
!isWellKnownSymbolSyntactically((<ComputedPropertyName>name).expression);
|
||||
}
|
||||
|
||||
@@ -1931,7 +1954,7 @@ namespace ts {
|
||||
return isPropertyAccessExpression(node) && isESSymbolIdentifier(node.expression);
|
||||
}
|
||||
|
||||
export function getPropertyNameForPropertyNameNode(name: DeclarationName): string {
|
||||
export function getPropertyNameForPropertyNameNode(name: DeclarationName | ParameterDeclaration): string {
|
||||
if (name.kind === SyntaxKind.Identifier || name.kind === SyntaxKind.StringLiteral || name.kind === SyntaxKind.NumericLiteral || name.kind === SyntaxKind.Parameter) {
|
||||
return (<Identifier | LiteralExpression>name).text;
|
||||
}
|
||||
@@ -2269,7 +2292,7 @@ namespace ts {
|
||||
case SyntaxKind.YieldExpression:
|
||||
return 2;
|
||||
|
||||
case SyntaxKind.SpreadElementExpression:
|
||||
case SyntaxKind.SpreadElement:
|
||||
return 1;
|
||||
|
||||
default:
|
||||
@@ -2593,22 +2616,39 @@ namespace ts {
|
||||
if (options.outFile || options.out) {
|
||||
const moduleKind = getEmitModuleKind(options);
|
||||
const moduleEmitEnabled = moduleKind === ModuleKind.AMD || moduleKind === ModuleKind.System;
|
||||
const sourceFiles = host.getSourceFiles();
|
||||
const sourceFiles = getAllEmittableSourceFiles();
|
||||
// Can emit only sources that are not declaration file and are either non module code or module with --module or --target es6 specified
|
||||
return filter(sourceFiles, moduleEmitEnabled ? isNonDeclarationFile : isBundleEmitNonExternalModule);
|
||||
}
|
||||
else {
|
||||
const sourceFiles = targetSourceFile === undefined ? host.getSourceFiles() : [targetSourceFile];
|
||||
return filter(sourceFiles, isNonDeclarationFile);
|
||||
const sourceFiles = targetSourceFile === undefined ? getAllEmittableSourceFiles() : [targetSourceFile];
|
||||
return filterSourceFilesInDirectory(sourceFiles, file => host.isSourceFileFromExternalLibrary(file));
|
||||
}
|
||||
|
||||
function getAllEmittableSourceFiles() {
|
||||
return options.noEmitForJsFiles ? filter(host.getSourceFiles(), sourceFile => !isSourceFileJavaScript(sourceFile)) : host.getSourceFiles();
|
||||
}
|
||||
}
|
||||
|
||||
/** Don't call this for `--outFile`, just for `--outDir` or plain emit. */
|
||||
export function filterSourceFilesInDirectory(sourceFiles: SourceFile[], isSourceFileFromExternalLibrary: (file: SourceFile) => boolean): SourceFile[] {
|
||||
return filter(sourceFiles, file => shouldEmitInDirectory(file, isSourceFileFromExternalLibrary));
|
||||
}
|
||||
|
||||
function isNonDeclarationFile(sourceFile: SourceFile) {
|
||||
return !isDeclarationFile(sourceFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a file should be emitted in a non-`--outFile` case.
|
||||
* Don't emit if source file is a declaration file, or was located under node_modules
|
||||
*/
|
||||
function shouldEmitInDirectory(sourceFile: SourceFile, isSourceFileFromExternalLibrary: (file: SourceFile) => boolean): boolean {
|
||||
return isNonDeclarationFile(sourceFile) && !isSourceFileFromExternalLibrary(sourceFile);
|
||||
}
|
||||
|
||||
function isBundleEmitNonExternalModule(sourceFile: SourceFile) {
|
||||
return !isDeclarationFile(sourceFile) && !isExternalModule(sourceFile);
|
||||
return isNonDeclarationFile(sourceFile) && !isExternalModule(sourceFile);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2632,7 +2672,7 @@ namespace ts {
|
||||
}
|
||||
else {
|
||||
for (const sourceFile of sourceFiles) {
|
||||
// Don't emit if source file is a declaration file, or was located under node_modules
|
||||
// Don't emit if source file is a declaration file, or was located under node_modules
|
||||
if (!isDeclarationFile(sourceFile) && !host.isSourceFileFromExternalLibrary(sourceFile)) {
|
||||
onSingleFileEmit(host, sourceFile);
|
||||
}
|
||||
@@ -2694,10 +2734,9 @@ namespace ts {
|
||||
onBundledEmit(host);
|
||||
}
|
||||
else {
|
||||
const sourceFiles = targetSourceFile === undefined ? host.getSourceFiles() : [targetSourceFile];
|
||||
const sourceFiles = targetSourceFile === undefined ? getSourceFilesToEmit(host) : [targetSourceFile];
|
||||
for (const sourceFile of sourceFiles) {
|
||||
// Don't emit if source file is a declaration file, or was located under node_modules
|
||||
if (!isDeclarationFile(sourceFile) && !host.isSourceFileFromExternalLibrary(sourceFile)) {
|
||||
if (shouldEmitInDirectory(sourceFile, file => host.isSourceFileFromExternalLibrary(file))) {
|
||||
onSingleFileEmit(host, sourceFile);
|
||||
}
|
||||
}
|
||||
@@ -2732,11 +2771,11 @@ namespace ts {
|
||||
function onBundledEmit(host: EmitHost) {
|
||||
// Can emit only sources that are not declaration file and are either non module code or module with
|
||||
// --module or --target es6 specified. Files included by searching under node_modules are also not emitted.
|
||||
const bundledSources = filter(host.getSourceFiles(),
|
||||
const bundledSources = filter(getSourceFilesToEmit(host),
|
||||
sourceFile => !isDeclarationFile(sourceFile) &&
|
||||
!host.isSourceFileFromExternalLibrary(sourceFile) &&
|
||||
(!isExternalModule(sourceFile) ||
|
||||
!!getEmitModuleKind(options)));
|
||||
!host.isSourceFileFromExternalLibrary(sourceFile) &&
|
||||
(!isExternalModule(sourceFile) ||
|
||||
!!getEmitModuleKind(options)));
|
||||
if (bundledSources.length) {
|
||||
const jsFilePath = options.outFile || options.out;
|
||||
const emitFileNames: EmitFileNames = {
|
||||
@@ -2922,7 +2961,7 @@ namespace ts {
|
||||
writeComment: (text: string, lineMap: number[], writer: EmitTextWriter, commentPos: number, commentEnd: number, newLine: string) => void,
|
||||
node: TextRange, newLine: string, removeComments: boolean) {
|
||||
let leadingComments: CommentRange[];
|
||||
let currentDetachedCommentInfo: {nodePos: number, detachedCommentEndPos: number};
|
||||
let currentDetachedCommentInfo: { nodePos: number, detachedCommentEndPos: number };
|
||||
if (removeComments) {
|
||||
// removeComments is true, only reserve pinned comment at the top of file
|
||||
// For example:
|
||||
@@ -3144,9 +3183,9 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
export function isAssignmentExpression(node: Node, excludeCompoundAssignment: true): node is AssignmentExpression<SyntaxKind.EqualsToken>;
|
||||
export function isAssignmentExpression(node: Node, excludeCompoundAssignment?: false): node is AssignmentExpression<AssignmentOperator>;
|
||||
export function isAssignmentExpression(node: Node, excludeCompoundAssignment?: boolean): node is AssignmentExpression<AssignmentOperator> {
|
||||
export function isAssignmentExpression(node: Node, excludeCompoundAssignment: true): node is AssignmentExpression<EqualsToken>;
|
||||
export function isAssignmentExpression(node: Node, excludeCompoundAssignment?: false): node is AssignmentExpression<AssignmentOperatorToken>;
|
||||
export function isAssignmentExpression(node: Node, excludeCompoundAssignment?: boolean): node is AssignmentExpression<AssignmentOperatorToken> {
|
||||
return isBinaryExpression(node)
|
||||
&& (excludeCompoundAssignment
|
||||
? node.operatorToken.kind === SyntaxKind.EqualsToken
|
||||
@@ -3271,10 +3310,10 @@ namespace ts {
|
||||
|
||||
function stringifyValue(value: any): string {
|
||||
return typeof value === "string" ? `"${escapeString(value)}"`
|
||||
: typeof value === "number" ? isFinite(value) ? String(value) : "null"
|
||||
: typeof value === "boolean" ? value ? "true" : "false"
|
||||
: typeof value === "object" && value ? isArray(value) ? cycleCheck(stringifyArray, value) : cycleCheck(stringifyObject, value)
|
||||
: /*fallback*/ "null";
|
||||
: typeof value === "number" ? isFinite(value) ? String(value) : "null"
|
||||
: typeof value === "boolean" ? value ? "true" : "false"
|
||||
: typeof value === "object" && value ? isArray(value) ? cycleCheck(stringifyArray, value) : cycleCheck(stringifyObject, value)
|
||||
: /*fallback*/ "null";
|
||||
}
|
||||
|
||||
function cycleCheck(cb: (value: any) => string, value: any) {
|
||||
@@ -3299,7 +3338,7 @@ namespace ts {
|
||||
|
||||
function stringifyProperty(memo: string, value: any, key: string) {
|
||||
return value === undefined || typeof value === "function" || key === "__cycle" ? memo
|
||||
: (memo ? memo + "," : memo) + `"${escapeString(key)}":${stringifyValue(value)}`;
|
||||
: (memo ? memo + "," : memo) + `"${escapeString(key)}":${stringifyValue(value)}`;
|
||||
}
|
||||
|
||||
const base64Digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||
@@ -3544,7 +3583,7 @@ namespace ts {
|
||||
* @param token The token.
|
||||
*/
|
||||
export function createTokenRange(pos: number, token: SyntaxKind): TextRange {
|
||||
return createRange(pos, pos + tokenToString(token).length);
|
||||
return createRange(pos, pos + tokenToString(token).length);
|
||||
}
|
||||
|
||||
export function rangeIsOnSingleLine(range: TextRange, sourceFile: SourceFile) {
|
||||
@@ -3764,6 +3803,7 @@ namespace ts {
|
||||
const kind = node.kind;
|
||||
return kind === SyntaxKind.PropertyAssignment
|
||||
|| kind === SyntaxKind.ShorthandPropertyAssignment
|
||||
|| kind === SyntaxKind.SpreadAssignment
|
||||
|| kind === SyntaxKind.MethodDeclaration
|
||||
|| kind === SyntaxKind.GetAccessor
|
||||
|| kind === SyntaxKind.SetAccessor
|
||||
@@ -3795,6 +3835,14 @@ namespace ts {
|
||||
|
||||
// Binding patterns
|
||||
|
||||
export function isArrayBindingPattern(node: Node): node is ArrayBindingPattern {
|
||||
return node.kind === SyntaxKind.ArrayBindingPattern;
|
||||
}
|
||||
|
||||
export function isObjectBindingPattern(node: Node): node is ObjectBindingPattern {
|
||||
return node.kind === SyntaxKind.ObjectBindingPattern;
|
||||
}
|
||||
|
||||
export function isBindingPattern(node: Node): node is BindingPattern {
|
||||
if (node) {
|
||||
const kind = node.kind;
|
||||
@@ -3805,6 +3853,12 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isAssignmentPattern(node: Node): node is AssignmentPattern {
|
||||
const kind = node.kind;
|
||||
return kind === SyntaxKind.ArrayLiteralExpression
|
||||
|| kind === SyntaxKind.ObjectLiteralExpression;
|
||||
}
|
||||
|
||||
export function isBindingElement(node: Node): node is BindingElement {
|
||||
return node.kind === SyntaxKind.BindingElement;
|
||||
}
|
||||
@@ -3815,6 +3869,55 @@ namespace ts {
|
||||
|| kind === SyntaxKind.OmittedExpression;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines whether the BindingOrAssignmentElement is a BindingElement-like declaration
|
||||
*/
|
||||
export function isDeclarationBindingElement(bindingElement: BindingOrAssignmentElement): bindingElement is VariableDeclaration | ParameterDeclaration | BindingElement {
|
||||
switch (bindingElement.kind) {
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
case SyntaxKind.Parameter:
|
||||
case SyntaxKind.BindingElement:
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a node is a BindingOrAssignmentPattern
|
||||
*/
|
||||
export function isBindingOrAssignmentPattern(node: BindingOrAssignmentElementTarget): node is BindingOrAssignmentPattern {
|
||||
return isObjectBindingOrAssignmentPattern(node)
|
||||
|| isArrayBindingOrAssignmentPattern(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a node is an ObjectBindingOrAssignmentPattern
|
||||
*/
|
||||
export function isObjectBindingOrAssignmentPattern(node: BindingOrAssignmentElementTarget): node is ObjectBindingOrAssignmentPattern {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ObjectBindingPattern:
|
||||
case SyntaxKind.ObjectLiteralExpression:
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a node is an ArrayBindingOrAssignmentPattern
|
||||
*/
|
||||
export function isArrayBindingOrAssignmentPattern(node: BindingOrAssignmentElementTarget): node is ArrayBindingOrAssignmentPattern {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ArrayBindingPattern:
|
||||
case SyntaxKind.ArrayLiteralExpression:
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Expression
|
||||
|
||||
export function isArrayLiteralExpression(node: Node): node is ArrayLiteralExpression {
|
||||
@@ -3851,8 +3954,8 @@ namespace ts {
|
||||
|| kind === SyntaxKind.NoSubstitutionTemplateLiteral;
|
||||
}
|
||||
|
||||
export function isSpreadElementExpression(node: Node): node is SpreadElementExpression {
|
||||
return node.kind === SyntaxKind.SpreadElementExpression;
|
||||
export function isSpreadExpression(node: Node): node is SpreadElement {
|
||||
return node.kind === SyntaxKind.SpreadElement;
|
||||
}
|
||||
|
||||
export function isExpressionWithTypeArguments(node: Node): node is ExpressionWithTypeArguments {
|
||||
@@ -3911,7 +4014,7 @@ namespace ts {
|
||||
|| kind === SyntaxKind.YieldExpression
|
||||
|| kind === SyntaxKind.ArrowFunction
|
||||
|| kind === SyntaxKind.BinaryExpression
|
||||
|| kind === SyntaxKind.SpreadElementExpression
|
||||
|| kind === SyntaxKind.SpreadElement
|
||||
|| kind === SyntaxKind.AsExpression
|
||||
|| kind === SyntaxKind.OmittedExpression
|
||||
|| kind === SyntaxKind.RawExpression
|
||||
@@ -4214,6 +4317,7 @@ namespace ts {
|
||||
namespace ts {
|
||||
export function getDefaultLibFileName(options: CompilerOptions): string {
|
||||
switch (options.target) {
|
||||
case ScriptTarget.ESNext:
|
||||
case ScriptTarget.ES2017:
|
||||
return "lib.es2017.d.ts";
|
||||
case ScriptTarget.ES2016:
|
||||
|
||||
+249
-189
@@ -99,20 +99,26 @@ namespace ts {
|
||||
return node ? f(initial, node) : initial;
|
||||
}
|
||||
|
||||
function reduceNodeArray<T>(nodes: Node[], f: (memo: T, nodes: Node[]) => T, initial: T) {
|
||||
return nodes ? f(initial, nodes) : initial;
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to `reduceLeft`, performs a reduction against each child of a node.
|
||||
* NOTE: Unlike `forEachChild`, this does *not* visit every node. Only nodes added to the
|
||||
* `nodeEdgeTraversalMap` above will be visited.
|
||||
*
|
||||
* @param node The node containing the children to reduce.
|
||||
* @param f The callback function
|
||||
* @param initial The initial value to supply to the reduction.
|
||||
* @param f The callback function
|
||||
*/
|
||||
export function reduceEachChild<T>(node: Node, f: (memo: T, node: Node) => T, initial: T): T {
|
||||
export function reduceEachChild<T>(node: Node, initial: T, cbNode: (memo: T, node: Node) => T, cbNodeArray?: (memo: T, nodes: Node[]) => T): T {
|
||||
if (node === undefined) {
|
||||
return initial;
|
||||
}
|
||||
|
||||
const reduceNodes: (nodes: Node[], f: (memo: T, node: Node | Node[]) => T, initial: T) => T = cbNodeArray ? reduceNodeArray : reduceLeft;
|
||||
const cbNodes = cbNodeArray || cbNode;
|
||||
const kind = node.kind;
|
||||
|
||||
// No need to visit nodes with no children.
|
||||
@@ -138,127 +144,127 @@ namespace ts {
|
||||
|
||||
// Names
|
||||
case SyntaxKind.ComputedPropertyName:
|
||||
result = reduceNode((<ComputedPropertyName>node).expression, f, result);
|
||||
result = reduceNode((<ComputedPropertyName>node).expression, cbNode, result);
|
||||
break;
|
||||
|
||||
// Signature elements
|
||||
case SyntaxKind.Parameter:
|
||||
result = reduceLeft((<ParameterDeclaration>node).decorators, f, result);
|
||||
result = reduceLeft((<ParameterDeclaration>node).modifiers, f, result);
|
||||
result = reduceNode((<ParameterDeclaration>node).name, f, result);
|
||||
result = reduceNode((<ParameterDeclaration>node).type, f, result);
|
||||
result = reduceNode((<ParameterDeclaration>node).initializer, f, result);
|
||||
result = reduceNodes((<ParameterDeclaration>node).decorators, cbNodes, result);
|
||||
result = reduceNodes((<ParameterDeclaration>node).modifiers, cbNodes, result);
|
||||
result = reduceNode((<ParameterDeclaration>node).name, cbNode, result);
|
||||
result = reduceNode((<ParameterDeclaration>node).type, cbNode, result);
|
||||
result = reduceNode((<ParameterDeclaration>node).initializer, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.Decorator:
|
||||
result = reduceNode((<Decorator>node).expression, f, result);
|
||||
result = reduceNode((<Decorator>node).expression, cbNode, result);
|
||||
break;
|
||||
|
||||
// Type member
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
result = reduceLeft((<PropertyDeclaration>node).decorators, f, result);
|
||||
result = reduceLeft((<PropertyDeclaration>node).modifiers, f, result);
|
||||
result = reduceNode((<PropertyDeclaration>node).name, f, result);
|
||||
result = reduceNode((<PropertyDeclaration>node).type, f, result);
|
||||
result = reduceNode((<PropertyDeclaration>node).initializer, f, result);
|
||||
result = reduceNodes((<PropertyDeclaration>node).decorators, cbNodes, result);
|
||||
result = reduceNodes((<PropertyDeclaration>node).modifiers, cbNodes, result);
|
||||
result = reduceNode((<PropertyDeclaration>node).name, cbNode, result);
|
||||
result = reduceNode((<PropertyDeclaration>node).type, cbNode, result);
|
||||
result = reduceNode((<PropertyDeclaration>node).initializer, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
result = reduceLeft((<MethodDeclaration>node).decorators, f, result);
|
||||
result = reduceLeft((<MethodDeclaration>node).modifiers, f, result);
|
||||
result = reduceNode((<MethodDeclaration>node).name, f, result);
|
||||
result = reduceLeft((<MethodDeclaration>node).typeParameters, f, result);
|
||||
result = reduceLeft((<MethodDeclaration>node).parameters, f, result);
|
||||
result = reduceNode((<MethodDeclaration>node).type, f, result);
|
||||
result = reduceNode((<MethodDeclaration>node).body, f, result);
|
||||
result = reduceNodes((<MethodDeclaration>node).decorators, cbNodes, result);
|
||||
result = reduceNodes((<MethodDeclaration>node).modifiers, cbNodes, result);
|
||||
result = reduceNode((<MethodDeclaration>node).name, cbNode, result);
|
||||
result = reduceNodes((<MethodDeclaration>node).typeParameters, cbNodes, result);
|
||||
result = reduceNodes((<MethodDeclaration>node).parameters, cbNodes, result);
|
||||
result = reduceNode((<MethodDeclaration>node).type, cbNode, result);
|
||||
result = reduceNode((<MethodDeclaration>node).body, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.Constructor:
|
||||
result = reduceLeft((<ConstructorDeclaration>node).modifiers, f, result);
|
||||
result = reduceLeft((<ConstructorDeclaration>node).parameters, f, result);
|
||||
result = reduceNode((<ConstructorDeclaration>node).body, f, result);
|
||||
result = reduceNodes((<ConstructorDeclaration>node).modifiers, cbNodes, result);
|
||||
result = reduceNodes((<ConstructorDeclaration>node).parameters, cbNodes, result);
|
||||
result = reduceNode((<ConstructorDeclaration>node).body, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.GetAccessor:
|
||||
result = reduceLeft((<GetAccessorDeclaration>node).decorators, f, result);
|
||||
result = reduceLeft((<GetAccessorDeclaration>node).modifiers, f, result);
|
||||
result = reduceNode((<GetAccessorDeclaration>node).name, f, result);
|
||||
result = reduceLeft((<GetAccessorDeclaration>node).parameters, f, result);
|
||||
result = reduceNode((<GetAccessorDeclaration>node).type, f, result);
|
||||
result = reduceNode((<GetAccessorDeclaration>node).body, f, result);
|
||||
result = reduceNodes((<GetAccessorDeclaration>node).decorators, cbNodes, result);
|
||||
result = reduceNodes((<GetAccessorDeclaration>node).modifiers, cbNodes, result);
|
||||
result = reduceNode((<GetAccessorDeclaration>node).name, cbNode, result);
|
||||
result = reduceNodes((<GetAccessorDeclaration>node).parameters, cbNodes, result);
|
||||
result = reduceNode((<GetAccessorDeclaration>node).type, cbNode, result);
|
||||
result = reduceNode((<GetAccessorDeclaration>node).body, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.SetAccessor:
|
||||
result = reduceLeft((<GetAccessorDeclaration>node).decorators, f, result);
|
||||
result = reduceLeft((<GetAccessorDeclaration>node).modifiers, f, result);
|
||||
result = reduceNode((<GetAccessorDeclaration>node).name, f, result);
|
||||
result = reduceLeft((<GetAccessorDeclaration>node).parameters, f, result);
|
||||
result = reduceNode((<GetAccessorDeclaration>node).body, f, result);
|
||||
result = reduceNodes((<GetAccessorDeclaration>node).decorators, cbNodes, result);
|
||||
result = reduceNodes((<GetAccessorDeclaration>node).modifiers, cbNodes, result);
|
||||
result = reduceNode((<GetAccessorDeclaration>node).name, cbNode, result);
|
||||
result = reduceNodes((<GetAccessorDeclaration>node).parameters, cbNodes, result);
|
||||
result = reduceNode((<GetAccessorDeclaration>node).body, cbNode, result);
|
||||
break;
|
||||
|
||||
// Binding patterns
|
||||
case SyntaxKind.ObjectBindingPattern:
|
||||
case SyntaxKind.ArrayBindingPattern:
|
||||
result = reduceLeft((<BindingPattern>node).elements, f, result);
|
||||
result = reduceNodes((<BindingPattern>node).elements, cbNodes, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.BindingElement:
|
||||
result = reduceNode((<BindingElement>node).propertyName, f, result);
|
||||
result = reduceNode((<BindingElement>node).name, f, result);
|
||||
result = reduceNode((<BindingElement>node).initializer, f, result);
|
||||
result = reduceNode((<BindingElement>node).propertyName, cbNode, result);
|
||||
result = reduceNode((<BindingElement>node).name, cbNode, result);
|
||||
result = reduceNode((<BindingElement>node).initializer, cbNode, result);
|
||||
break;
|
||||
|
||||
// Expression
|
||||
case SyntaxKind.ArrayLiteralExpression:
|
||||
result = reduceLeft((<ArrayLiteralExpression>node).elements, f, result);
|
||||
result = reduceNodes((<ArrayLiteralExpression>node).elements, cbNodes, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.ObjectLiteralExpression:
|
||||
result = reduceLeft((<ObjectLiteralExpression>node).properties, f, result);
|
||||
result = reduceNodes((<ObjectLiteralExpression>node).properties, cbNodes, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.PropertyAccessExpression:
|
||||
result = reduceNode((<PropertyAccessExpression>node).expression, f, result);
|
||||
result = reduceNode((<PropertyAccessExpression>node).name, f, result);
|
||||
result = reduceNode((<PropertyAccessExpression>node).expression, cbNode, result);
|
||||
result = reduceNode((<PropertyAccessExpression>node).name, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.ElementAccessExpression:
|
||||
result = reduceNode((<ElementAccessExpression>node).expression, f, result);
|
||||
result = reduceNode((<ElementAccessExpression>node).argumentExpression, f, result);
|
||||
result = reduceNode((<ElementAccessExpression>node).expression, cbNode, result);
|
||||
result = reduceNode((<ElementAccessExpression>node).argumentExpression, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.CallExpression:
|
||||
result = reduceNode((<CallExpression>node).expression, f, result);
|
||||
result = reduceLeft((<CallExpression>node).typeArguments, f, result);
|
||||
result = reduceLeft((<CallExpression>node).arguments, f, result);
|
||||
result = reduceNode((<CallExpression>node).expression, cbNode, result);
|
||||
result = reduceNodes((<CallExpression>node).typeArguments, cbNodes, result);
|
||||
result = reduceNodes((<CallExpression>node).arguments, cbNodes, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.NewExpression:
|
||||
result = reduceNode((<NewExpression>node).expression, f, result);
|
||||
result = reduceLeft((<NewExpression>node).typeArguments, f, result);
|
||||
result = reduceLeft((<NewExpression>node).arguments, f, result);
|
||||
result = reduceNode((<NewExpression>node).expression, cbNode, result);
|
||||
result = reduceNodes((<NewExpression>node).typeArguments, cbNodes, result);
|
||||
result = reduceNodes((<NewExpression>node).arguments, cbNodes, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.TaggedTemplateExpression:
|
||||
result = reduceNode((<TaggedTemplateExpression>node).tag, f, result);
|
||||
result = reduceNode((<TaggedTemplateExpression>node).template, f, result);
|
||||
result = reduceNode((<TaggedTemplateExpression>node).tag, cbNode, result);
|
||||
result = reduceNode((<TaggedTemplateExpression>node).template, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.FunctionExpression:
|
||||
result = reduceLeft((<FunctionExpression>node).modifiers, f, result);
|
||||
result = reduceNode((<FunctionExpression>node).name, f, result);
|
||||
result = reduceLeft((<FunctionExpression>node).typeParameters, f, result);
|
||||
result = reduceLeft((<FunctionExpression>node).parameters, f, result);
|
||||
result = reduceNode((<FunctionExpression>node).type, f, result);
|
||||
result = reduceNode((<FunctionExpression>node).body, f, result);
|
||||
result = reduceNodes((<FunctionExpression>node).modifiers, cbNodes, result);
|
||||
result = reduceNode((<FunctionExpression>node).name, cbNode, result);
|
||||
result = reduceNodes((<FunctionExpression>node).typeParameters, cbNodes, result);
|
||||
result = reduceNodes((<FunctionExpression>node).parameters, cbNodes, result);
|
||||
result = reduceNode((<FunctionExpression>node).type, cbNode, result);
|
||||
result = reduceNode((<FunctionExpression>node).body, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.ArrowFunction:
|
||||
result = reduceLeft((<ArrowFunction>node).modifiers, f, result);
|
||||
result = reduceLeft((<ArrowFunction>node).typeParameters, f, result);
|
||||
result = reduceLeft((<ArrowFunction>node).parameters, f, result);
|
||||
result = reduceNode((<ArrowFunction>node).type, f, result);
|
||||
result = reduceNode((<ArrowFunction>node).body, f, result);
|
||||
result = reduceNodes((<ArrowFunction>node).modifiers, cbNodes, result);
|
||||
result = reduceNodes((<ArrowFunction>node).typeParameters, cbNodes, result);
|
||||
result = reduceNodes((<ArrowFunction>node).parameters, cbNodes, result);
|
||||
result = reduceNode((<ArrowFunction>node).type, cbNode, result);
|
||||
result = reduceNode((<ArrowFunction>node).body, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.ParenthesizedExpression:
|
||||
@@ -267,256 +273,260 @@ namespace ts {
|
||||
case SyntaxKind.VoidExpression:
|
||||
case SyntaxKind.AwaitExpression:
|
||||
case SyntaxKind.YieldExpression:
|
||||
case SyntaxKind.SpreadElementExpression:
|
||||
case SyntaxKind.SpreadElement:
|
||||
case SyntaxKind.NonNullExpression:
|
||||
result = reduceNode((<ParenthesizedExpression | DeleteExpression | TypeOfExpression | VoidExpression | AwaitExpression | YieldExpression | SpreadElementExpression | NonNullExpression>node).expression, f, result);
|
||||
result = reduceNode((<ParenthesizedExpression | DeleteExpression | TypeOfExpression | VoidExpression | AwaitExpression | YieldExpression | SpreadElement | NonNullExpression>node).expression, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.PrefixUnaryExpression:
|
||||
case SyntaxKind.PostfixUnaryExpression:
|
||||
result = reduceNode((<PrefixUnaryExpression | PostfixUnaryExpression>node).operand, f, result);
|
||||
result = reduceNode((<PrefixUnaryExpression | PostfixUnaryExpression>node).operand, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.BinaryExpression:
|
||||
result = reduceNode((<BinaryExpression>node).left, f, result);
|
||||
result = reduceNode((<BinaryExpression>node).right, f, result);
|
||||
result = reduceNode((<BinaryExpression>node).left, cbNode, result);
|
||||
result = reduceNode((<BinaryExpression>node).right, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.ConditionalExpression:
|
||||
result = reduceNode((<ConditionalExpression>node).condition, f, result);
|
||||
result = reduceNode((<ConditionalExpression>node).whenTrue, f, result);
|
||||
result = reduceNode((<ConditionalExpression>node).whenFalse, f, result);
|
||||
result = reduceNode((<ConditionalExpression>node).condition, cbNode, result);
|
||||
result = reduceNode((<ConditionalExpression>node).whenTrue, cbNode, result);
|
||||
result = reduceNode((<ConditionalExpression>node).whenFalse, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.TemplateExpression:
|
||||
result = reduceNode((<TemplateExpression>node).head, f, result);
|
||||
result = reduceLeft((<TemplateExpression>node).templateSpans, f, result);
|
||||
result = reduceNode((<TemplateExpression>node).head, cbNode, result);
|
||||
result = reduceNodes((<TemplateExpression>node).templateSpans, cbNodes, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.ClassExpression:
|
||||
result = reduceLeft((<ClassExpression>node).modifiers, f, result);
|
||||
result = reduceNode((<ClassExpression>node).name, f, result);
|
||||
result = reduceLeft((<ClassExpression>node).typeParameters, f, result);
|
||||
result = reduceLeft((<ClassExpression>node).heritageClauses, f, result);
|
||||
result = reduceLeft((<ClassExpression>node).members, f, result);
|
||||
result = reduceNodes((<ClassExpression>node).modifiers, cbNodes, result);
|
||||
result = reduceNode((<ClassExpression>node).name, cbNode, result);
|
||||
result = reduceNodes((<ClassExpression>node).typeParameters, cbNodes, result);
|
||||
result = reduceNodes((<ClassExpression>node).heritageClauses, cbNodes, result);
|
||||
result = reduceNodes((<ClassExpression>node).members, cbNodes, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.ExpressionWithTypeArguments:
|
||||
result = reduceNode((<ExpressionWithTypeArguments>node).expression, f, result);
|
||||
result = reduceLeft((<ExpressionWithTypeArguments>node).typeArguments, f, result);
|
||||
result = reduceNode((<ExpressionWithTypeArguments>node).expression, cbNode, result);
|
||||
result = reduceNodes((<ExpressionWithTypeArguments>node).typeArguments, cbNodes, result);
|
||||
break;
|
||||
|
||||
// Misc
|
||||
case SyntaxKind.TemplateSpan:
|
||||
result = reduceNode((<TemplateSpan>node).expression, f, result);
|
||||
result = reduceNode((<TemplateSpan>node).literal, f, result);
|
||||
result = reduceNode((<TemplateSpan>node).expression, cbNode, result);
|
||||
result = reduceNode((<TemplateSpan>node).literal, cbNode, result);
|
||||
break;
|
||||
|
||||
// Element
|
||||
case SyntaxKind.Block:
|
||||
result = reduceLeft((<Block>node).statements, f, result);
|
||||
result = reduceNodes((<Block>node).statements, cbNodes, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.VariableStatement:
|
||||
result = reduceLeft((<VariableStatement>node).modifiers, f, result);
|
||||
result = reduceNode((<VariableStatement>node).declarationList, f, result);
|
||||
result = reduceNodes((<VariableStatement>node).modifiers, cbNodes, result);
|
||||
result = reduceNode((<VariableStatement>node).declarationList, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.ExpressionStatement:
|
||||
result = reduceNode((<ExpressionStatement>node).expression, f, result);
|
||||
result = reduceNode((<ExpressionStatement>node).expression, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.IfStatement:
|
||||
result = reduceNode((<IfStatement>node).expression, f, result);
|
||||
result = reduceNode((<IfStatement>node).thenStatement, f, result);
|
||||
result = reduceNode((<IfStatement>node).elseStatement, f, result);
|
||||
result = reduceNode((<IfStatement>node).expression, cbNode, result);
|
||||
result = reduceNode((<IfStatement>node).thenStatement, cbNode, result);
|
||||
result = reduceNode((<IfStatement>node).elseStatement, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.DoStatement:
|
||||
result = reduceNode((<DoStatement>node).statement, f, result);
|
||||
result = reduceNode((<DoStatement>node).expression, f, result);
|
||||
result = reduceNode((<DoStatement>node).statement, cbNode, result);
|
||||
result = reduceNode((<DoStatement>node).expression, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.WhileStatement:
|
||||
case SyntaxKind.WithStatement:
|
||||
result = reduceNode((<WhileStatement | WithStatement>node).expression, f, result);
|
||||
result = reduceNode((<WhileStatement | WithStatement>node).statement, f, result);
|
||||
result = reduceNode((<WhileStatement | WithStatement>node).expression, cbNode, result);
|
||||
result = reduceNode((<WhileStatement | WithStatement>node).statement, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.ForStatement:
|
||||
result = reduceNode((<ForStatement>node).initializer, f, result);
|
||||
result = reduceNode((<ForStatement>node).condition, f, result);
|
||||
result = reduceNode((<ForStatement>node).incrementor, f, result);
|
||||
result = reduceNode((<ForStatement>node).statement, f, result);
|
||||
result = reduceNode((<ForStatement>node).initializer, cbNode, result);
|
||||
result = reduceNode((<ForStatement>node).condition, cbNode, result);
|
||||
result = reduceNode((<ForStatement>node).incrementor, cbNode, result);
|
||||
result = reduceNode((<ForStatement>node).statement, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.ForInStatement:
|
||||
case SyntaxKind.ForOfStatement:
|
||||
result = reduceNode((<ForInStatement | ForOfStatement>node).initializer, f, result);
|
||||
result = reduceNode((<ForInStatement | ForOfStatement>node).expression, f, result);
|
||||
result = reduceNode((<ForInStatement | ForOfStatement>node).statement, f, result);
|
||||
result = reduceNode((<ForInStatement | ForOfStatement>node).initializer, cbNode, result);
|
||||
result = reduceNode((<ForInStatement | ForOfStatement>node).expression, cbNode, result);
|
||||
result = reduceNode((<ForInStatement | ForOfStatement>node).statement, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.ReturnStatement:
|
||||
case SyntaxKind.ThrowStatement:
|
||||
result = reduceNode((<ReturnStatement>node).expression, f, result);
|
||||
result = reduceNode((<ReturnStatement>node).expression, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.SwitchStatement:
|
||||
result = reduceNode((<SwitchStatement>node).expression, f, result);
|
||||
result = reduceNode((<SwitchStatement>node).caseBlock, f, result);
|
||||
result = reduceNode((<SwitchStatement>node).expression, cbNode, result);
|
||||
result = reduceNode((<SwitchStatement>node).caseBlock, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.LabeledStatement:
|
||||
result = reduceNode((<LabeledStatement>node).label, f, result);
|
||||
result = reduceNode((<LabeledStatement>node).statement, f, result);
|
||||
result = reduceNode((<LabeledStatement>node).label, cbNode, result);
|
||||
result = reduceNode((<LabeledStatement>node).statement, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.TryStatement:
|
||||
result = reduceNode((<TryStatement>node).tryBlock, f, result);
|
||||
result = reduceNode((<TryStatement>node).catchClause, f, result);
|
||||
result = reduceNode((<TryStatement>node).finallyBlock, f, result);
|
||||
result = reduceNode((<TryStatement>node).tryBlock, cbNode, result);
|
||||
result = reduceNode((<TryStatement>node).catchClause, cbNode, result);
|
||||
result = reduceNode((<TryStatement>node).finallyBlock, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
result = reduceNode((<VariableDeclaration>node).name, f, result);
|
||||
result = reduceNode((<VariableDeclaration>node).type, f, result);
|
||||
result = reduceNode((<VariableDeclaration>node).initializer, f, result);
|
||||
result = reduceNode((<VariableDeclaration>node).name, cbNode, result);
|
||||
result = reduceNode((<VariableDeclaration>node).type, cbNode, result);
|
||||
result = reduceNode((<VariableDeclaration>node).initializer, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.VariableDeclarationList:
|
||||
result = reduceLeft((<VariableDeclarationList>node).declarations, f, result);
|
||||
result = reduceNodes((<VariableDeclarationList>node).declarations, cbNodes, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
result = reduceLeft((<FunctionDeclaration>node).decorators, f, result);
|
||||
result = reduceLeft((<FunctionDeclaration>node).modifiers, f, result);
|
||||
result = reduceNode((<FunctionDeclaration>node).name, f, result);
|
||||
result = reduceLeft((<FunctionDeclaration>node).typeParameters, f, result);
|
||||
result = reduceLeft((<FunctionDeclaration>node).parameters, f, result);
|
||||
result = reduceNode((<FunctionDeclaration>node).type, f, result);
|
||||
result = reduceNode((<FunctionDeclaration>node).body, f, result);
|
||||
result = reduceNodes((<FunctionDeclaration>node).decorators, cbNodes, result);
|
||||
result = reduceNodes((<FunctionDeclaration>node).modifiers, cbNodes, result);
|
||||
result = reduceNode((<FunctionDeclaration>node).name, cbNode, result);
|
||||
result = reduceNodes((<FunctionDeclaration>node).typeParameters, cbNodes, result);
|
||||
result = reduceNodes((<FunctionDeclaration>node).parameters, cbNodes, result);
|
||||
result = reduceNode((<FunctionDeclaration>node).type, cbNode, result);
|
||||
result = reduceNode((<FunctionDeclaration>node).body, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
result = reduceLeft((<ClassDeclaration>node).decorators, f, result);
|
||||
result = reduceLeft((<ClassDeclaration>node).modifiers, f, result);
|
||||
result = reduceNode((<ClassDeclaration>node).name, f, result);
|
||||
result = reduceLeft((<ClassDeclaration>node).typeParameters, f, result);
|
||||
result = reduceLeft((<ClassDeclaration>node).heritageClauses, f, result);
|
||||
result = reduceLeft((<ClassDeclaration>node).members, f, result);
|
||||
result = reduceNodes((<ClassDeclaration>node).decorators, cbNodes, result);
|
||||
result = reduceNodes((<ClassDeclaration>node).modifiers, cbNodes, result);
|
||||
result = reduceNode((<ClassDeclaration>node).name, cbNode, result);
|
||||
result = reduceNodes((<ClassDeclaration>node).typeParameters, cbNodes, result);
|
||||
result = reduceNodes((<ClassDeclaration>node).heritageClauses, cbNodes, result);
|
||||
result = reduceNodes((<ClassDeclaration>node).members, cbNodes, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.CaseBlock:
|
||||
result = reduceLeft((<CaseBlock>node).clauses, f, result);
|
||||
result = reduceNodes((<CaseBlock>node).clauses, cbNodes, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.ImportDeclaration:
|
||||
result = reduceLeft((<ImportDeclaration>node).decorators, f, result);
|
||||
result = reduceLeft((<ImportDeclaration>node).modifiers, f, result);
|
||||
result = reduceNode((<ImportDeclaration>node).importClause, f, result);
|
||||
result = reduceNode((<ImportDeclaration>node).moduleSpecifier, f, result);
|
||||
result = reduceNodes((<ImportDeclaration>node).decorators, cbNodes, result);
|
||||
result = reduceNodes((<ImportDeclaration>node).modifiers, cbNodes, result);
|
||||
result = reduceNode((<ImportDeclaration>node).importClause, cbNode, result);
|
||||
result = reduceNode((<ImportDeclaration>node).moduleSpecifier, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.ImportClause:
|
||||
result = reduceNode((<ImportClause>node).name, f, result);
|
||||
result = reduceNode((<ImportClause>node).namedBindings, f, result);
|
||||
result = reduceNode((<ImportClause>node).name, cbNode, result);
|
||||
result = reduceNode((<ImportClause>node).namedBindings, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.NamespaceImport:
|
||||
result = reduceNode((<NamespaceImport>node).name, f, result);
|
||||
result = reduceNode((<NamespaceImport>node).name, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.NamedImports:
|
||||
case SyntaxKind.NamedExports:
|
||||
result = reduceLeft((<NamedImports | NamedExports>node).elements, f, result);
|
||||
result = reduceNodes((<NamedImports | NamedExports>node).elements, cbNodes, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.ImportSpecifier:
|
||||
case SyntaxKind.ExportSpecifier:
|
||||
result = reduceNode((<ImportSpecifier | ExportSpecifier>node).propertyName, f, result);
|
||||
result = reduceNode((<ImportSpecifier | ExportSpecifier>node).name, f, result);
|
||||
result = reduceNode((<ImportSpecifier | ExportSpecifier>node).propertyName, cbNode, result);
|
||||
result = reduceNode((<ImportSpecifier | ExportSpecifier>node).name, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.ExportAssignment:
|
||||
result = reduceLeft((<ExportAssignment>node).decorators, f, result);
|
||||
result = reduceLeft((<ExportAssignment>node).modifiers, f, result);
|
||||
result = reduceNode((<ExportAssignment>node).expression, f, result);
|
||||
result = reduceLeft((<ExportAssignment>node).decorators, cbNode, result);
|
||||
result = reduceLeft((<ExportAssignment>node).modifiers, cbNode, result);
|
||||
result = reduceNode((<ExportAssignment>node).expression, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.ExportDeclaration:
|
||||
result = reduceLeft((<ExportDeclaration>node).decorators, f, result);
|
||||
result = reduceLeft((<ExportDeclaration>node).modifiers, f, result);
|
||||
result = reduceNode((<ExportDeclaration>node).exportClause, f, result);
|
||||
result = reduceNode((<ExportDeclaration>node).moduleSpecifier, f, result);
|
||||
result = reduceLeft((<ExportDeclaration>node).decorators, cbNode, result);
|
||||
result = reduceLeft((<ExportDeclaration>node).modifiers, cbNode, result);
|
||||
result = reduceNode((<ExportDeclaration>node).exportClause, cbNode, result);
|
||||
result = reduceNode((<ExportDeclaration>node).moduleSpecifier, cbNode, result);
|
||||
break;
|
||||
|
||||
// JSX
|
||||
case SyntaxKind.JsxElement:
|
||||
result = reduceNode((<JsxElement>node).openingElement, f, result);
|
||||
result = reduceLeft((<JsxElement>node).children, f, result);
|
||||
result = reduceNode((<JsxElement>node).closingElement, f, result);
|
||||
result = reduceNode((<JsxElement>node).openingElement, cbNode, result);
|
||||
result = reduceLeft((<JsxElement>node).children, cbNode, result);
|
||||
result = reduceNode((<JsxElement>node).closingElement, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.JsxSelfClosingElement:
|
||||
case SyntaxKind.JsxOpeningElement:
|
||||
result = reduceNode((<JsxSelfClosingElement | JsxOpeningElement>node).tagName, f, result);
|
||||
result = reduceLeft((<JsxSelfClosingElement | JsxOpeningElement>node).attributes, f, result);
|
||||
result = reduceNode((<JsxSelfClosingElement | JsxOpeningElement>node).tagName, cbNode, result);
|
||||
result = reduceNodes((<JsxSelfClosingElement | JsxOpeningElement>node).attributes, cbNodes, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.JsxClosingElement:
|
||||
result = reduceNode((<JsxClosingElement>node).tagName, f, result);
|
||||
result = reduceNode((<JsxClosingElement>node).tagName, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.JsxAttribute:
|
||||
result = reduceNode((<JsxAttribute>node).name, f, result);
|
||||
result = reduceNode((<JsxAttribute>node).initializer, f, result);
|
||||
result = reduceNode((<JsxAttribute>node).name, cbNode, result);
|
||||
result = reduceNode((<JsxAttribute>node).initializer, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.JsxSpreadAttribute:
|
||||
result = reduceNode((<JsxSpreadAttribute>node).expression, f, result);
|
||||
result = reduceNode((<JsxSpreadAttribute>node).expression, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.JsxExpression:
|
||||
result = reduceNode((<JsxExpression>node).expression, f, result);
|
||||
result = reduceNode((<JsxExpression>node).expression, cbNode, result);
|
||||
break;
|
||||
|
||||
// Clauses
|
||||
case SyntaxKind.CaseClause:
|
||||
result = reduceNode((<CaseClause>node).expression, f, result);
|
||||
result = reduceNode((<CaseClause>node).expression, cbNode, result);
|
||||
// fall-through
|
||||
|
||||
case SyntaxKind.DefaultClause:
|
||||
result = reduceLeft((<CaseClause | DefaultClause>node).statements, f, result);
|
||||
result = reduceNodes((<CaseClause | DefaultClause>node).statements, cbNodes, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.HeritageClause:
|
||||
result = reduceLeft((<HeritageClause>node).types, f, result);
|
||||
result = reduceNodes((<HeritageClause>node).types, cbNodes, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.CatchClause:
|
||||
result = reduceNode((<CatchClause>node).variableDeclaration, f, result);
|
||||
result = reduceNode((<CatchClause>node).block, f, result);
|
||||
result = reduceNode((<CatchClause>node).variableDeclaration, cbNode, result);
|
||||
result = reduceNode((<CatchClause>node).block, cbNode, result);
|
||||
break;
|
||||
|
||||
// Property assignments
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
result = reduceNode((<PropertyAssignment>node).name, f, result);
|
||||
result = reduceNode((<PropertyAssignment>node).initializer, f, result);
|
||||
result = reduceNode((<PropertyAssignment>node).name, cbNode, result);
|
||||
result = reduceNode((<PropertyAssignment>node).initializer, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.ShorthandPropertyAssignment:
|
||||
result = reduceNode((<ShorthandPropertyAssignment>node).name, f, result);
|
||||
result = reduceNode((<ShorthandPropertyAssignment>node).objectAssignmentInitializer, f, result);
|
||||
result = reduceNode((<ShorthandPropertyAssignment>node).name, cbNode, result);
|
||||
result = reduceNode((<ShorthandPropertyAssignment>node).objectAssignmentInitializer, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.SpreadAssignment:
|
||||
result = reduceNode((node as SpreadAssignment).expression, cbNode, result);
|
||||
break;
|
||||
|
||||
// Top-level nodes
|
||||
case SyntaxKind.SourceFile:
|
||||
result = reduceLeft((<SourceFile>node).statements, f, result);
|
||||
result = reduceNodes((<SourceFile>node).statements, cbNodes, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.PartiallyEmittedExpression:
|
||||
result = reduceNode((<PartiallyEmittedExpression>node).expression, f, result);
|
||||
result = reduceNode((<PartiallyEmittedExpression>node).expression, cbNode, result);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -526,8 +536,8 @@ namespace ts {
|
||||
const value = (<MapLike<any>>node)[edge.name];
|
||||
if (value !== undefined) {
|
||||
result = isArray(value)
|
||||
? reduceLeft(<NodeArray<Node>>value, f, result)
|
||||
: f(result, <Node>value);
|
||||
? reduceNodes(<NodeArray<Node>>value, cbNodes, result)
|
||||
: cbNode(result, <Node>value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -665,8 +675,8 @@ namespace ts {
|
||||
if (ensureUseStrict && !startsWithUseStrict(statements)) {
|
||||
statements = createNodeArray([createStatement(createLiteral("use strict")), ...statements], statements);
|
||||
}
|
||||
statements = mergeLexicalEnvironment(statements, context.endLexicalEnvironment());
|
||||
return statements;
|
||||
const declarations = context.endLexicalEnvironment();
|
||||
return createNodeArray(concatenate(statements, declarations), statements);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -684,15 +694,15 @@ namespace ts {
|
||||
* Resumes a suspended lexical environment and visits a function body, ending the lexical
|
||||
* environment and merging hoisted declarations upon completion.
|
||||
*/
|
||||
export function visitFunctionBody(node: FunctionBody, visitor: (node: Node) => VisitResult<Node>, context: TransformationContext, optional?: boolean): FunctionBody;
|
||||
export function visitFunctionBody(node: FunctionBody, visitor: (node: Node) => VisitResult<Node>, context: TransformationContext): FunctionBody;
|
||||
/**
|
||||
* Resumes a suspended lexical environment and visits a concise body, ending the lexical
|
||||
* environment and merging hoisted declarations upon completion.
|
||||
*/
|
||||
export function visitFunctionBody(node: ConciseBody, visitor: (node: Node) => VisitResult<Node>, context: TransformationContext): ConciseBody;
|
||||
export function visitFunctionBody(node: ConciseBody, visitor: (node: Node) => VisitResult<Node>, context: TransformationContext, optional?: boolean): ConciseBody {
|
||||
export function visitFunctionBody(node: ConciseBody, visitor: (node: Node) => VisitResult<Node>, context: TransformationContext): ConciseBody {
|
||||
context.resumeLexicalEnvironment();
|
||||
const updated = visitNode(node, visitor, isConciseBody, optional);
|
||||
const updated = visitNode(node, visitor, isConciseBody);
|
||||
const declarations = context.endLexicalEnvironment();
|
||||
if (some(declarations)) {
|
||||
const block = convertToFunctionBody(updated);
|
||||
@@ -744,6 +754,7 @@ namespace ts {
|
||||
return updateParameter(<ParameterDeclaration>node,
|
||||
visitNodes((<ParameterDeclaration>node).decorators, visitor, isDecorator),
|
||||
visitNodes((<ParameterDeclaration>node).modifiers, visitor, isModifier),
|
||||
(<ParameterDeclaration>node).dotDotDotToken,
|
||||
visitNode((<ParameterDeclaration>node).name, visitor, isBindingName),
|
||||
visitNode((<ParameterDeclaration>node).type, visitor, isTypeNode, /*optional*/ true),
|
||||
visitNode((<ParameterDeclaration>node).initializer, visitor, isExpression, /*optional*/ true));
|
||||
@@ -766,14 +777,14 @@ namespace ts {
|
||||
visitNodes((<MethodDeclaration>node).typeParameters, visitor, isTypeParameter),
|
||||
visitParameterList((<MethodDeclaration>node).parameters, visitor, context),
|
||||
visitNode((<MethodDeclaration>node).type, visitor, isTypeNode, /*optional*/ true),
|
||||
visitFunctionBody((<MethodDeclaration>node).body, visitor, context, /*optional*/ true));
|
||||
visitFunctionBody((<MethodDeclaration>node).body, visitor, context));
|
||||
|
||||
case SyntaxKind.Constructor:
|
||||
return updateConstructor(<ConstructorDeclaration>node,
|
||||
visitNodes((<ConstructorDeclaration>node).decorators, visitor, isDecorator),
|
||||
visitNodes((<ConstructorDeclaration>node).modifiers, visitor, isModifier),
|
||||
visitParameterList((<ConstructorDeclaration>node).parameters, visitor, context),
|
||||
visitFunctionBody((<ConstructorDeclaration>node).body, visitor, context, /*optional*/ true));
|
||||
visitFunctionBody((<ConstructorDeclaration>node).body, visitor, context));
|
||||
|
||||
case SyntaxKind.GetAccessor:
|
||||
return updateGetAccessor(<GetAccessorDeclaration>node,
|
||||
@@ -782,7 +793,7 @@ namespace ts {
|
||||
visitNode((<GetAccessorDeclaration>node).name, visitor, isPropertyName),
|
||||
visitParameterList((<GetAccessorDeclaration>node).parameters, visitor, context),
|
||||
visitNode((<GetAccessorDeclaration>node).type, visitor, isTypeNode, /*optional*/ true),
|
||||
visitFunctionBody((<GetAccessorDeclaration>node).body, visitor, context, /*optional*/ true));
|
||||
visitFunctionBody((<GetAccessorDeclaration>node).body, visitor, context));
|
||||
|
||||
case SyntaxKind.SetAccessor:
|
||||
return updateSetAccessor(<SetAccessorDeclaration>node,
|
||||
@@ -790,7 +801,7 @@ namespace ts {
|
||||
visitNodes((<SetAccessorDeclaration>node).modifiers, visitor, isModifier),
|
||||
visitNode((<SetAccessorDeclaration>node).name, visitor, isPropertyName),
|
||||
visitParameterList((<SetAccessorDeclaration>node).parameters, visitor, context),
|
||||
visitFunctionBody((<SetAccessorDeclaration>node).body, visitor, context, /*optional*/ true));
|
||||
visitFunctionBody((<SetAccessorDeclaration>node).body, visitor, context));
|
||||
|
||||
// Binding patterns
|
||||
case SyntaxKind.ObjectBindingPattern:
|
||||
@@ -803,6 +814,7 @@ namespace ts {
|
||||
|
||||
case SyntaxKind.BindingElement:
|
||||
return updateBindingElement(<BindingElement>node,
|
||||
(<BindingElement>node).dotDotDotToken,
|
||||
visitNode((<BindingElement>node).propertyName, visitor, isPropertyName, /*optional*/ true),
|
||||
visitNode((<BindingElement>node).name, visitor, isBindingName),
|
||||
visitNode((<BindingElement>node).initializer, visitor, isExpression, /*optional*/ true));
|
||||
@@ -855,7 +867,7 @@ namespace ts {
|
||||
visitNodes((<FunctionExpression>node).typeParameters, visitor, isTypeParameter),
|
||||
visitParameterList((<FunctionExpression>node).parameters, visitor, context),
|
||||
visitNode((<FunctionExpression>node).type, visitor, isTypeNode, /*optional*/ true),
|
||||
visitFunctionBody((<FunctionExpression>node).body, visitor, context, /*optional*/ true));
|
||||
visitFunctionBody((<FunctionExpression>node).body, visitor, context));
|
||||
|
||||
case SyntaxKind.ArrowFunction:
|
||||
return updateArrowFunction(<ArrowFunction>node,
|
||||
@@ -909,9 +921,9 @@ namespace ts {
|
||||
return updateYield(<YieldExpression>node,
|
||||
visitNode((<YieldExpression>node).expression, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.SpreadElementExpression:
|
||||
return updateSpread(<SpreadElementExpression>node,
|
||||
visitNode((<SpreadElementExpression>node).expression, visitor, isExpression));
|
||||
case SyntaxKind.SpreadElement:
|
||||
return updateSpread(<SpreadElement>node,
|
||||
visitNode((<SpreadElement>node).expression, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.ClassExpression:
|
||||
return updateClassExpression(<ClassExpression>node,
|
||||
@@ -1037,7 +1049,7 @@ namespace ts {
|
||||
visitNodes((<FunctionDeclaration>node).typeParameters, visitor, isTypeParameter),
|
||||
visitParameterList((<FunctionDeclaration>node).parameters, visitor, context),
|
||||
visitNode((<FunctionDeclaration>node).type, visitor, isTypeNode, /*optional*/ true),
|
||||
visitFunctionBody((<FunctionExpression>node).body, visitor, context, /*optional*/ true));
|
||||
visitFunctionBody((<FunctionExpression>node).body, visitor, context));
|
||||
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
return updateClassDeclaration(<ClassDeclaration>node,
|
||||
@@ -1163,7 +1175,11 @@ namespace ts {
|
||||
visitNode((<ShorthandPropertyAssignment>node).name, visitor, isIdentifier),
|
||||
visitNode((<ShorthandPropertyAssignment>node).objectAssignmentInitializer, visitor, isExpression));
|
||||
|
||||
// Top-level nodes
|
||||
case SyntaxKind.SpreadAssignment:
|
||||
return updateSpreadAssignment(node as SpreadAssignment,
|
||||
visitNode((node as SpreadAssignment).expression, visitor, isExpression));
|
||||
|
||||
// Top-level nodes
|
||||
case SyntaxKind.SourceFile:
|
||||
return updateSourceFileNode(<SourceFile>node,
|
||||
visitLexicalEnvironment((<SourceFile>node).statements, visitor, context));
|
||||
@@ -1262,13 +1278,25 @@ namespace ts {
|
||||
if (node === undefined) {
|
||||
return TransformFlags.None;
|
||||
}
|
||||
else if (node.transformFlags & TransformFlags.HasComputedFlags) {
|
||||
if (node.transformFlags & TransformFlags.HasComputedFlags) {
|
||||
return node.transformFlags & ~getTransformFlagsSubtreeExclusions(node.kind);
|
||||
}
|
||||
else {
|
||||
const subtreeFlags = aggregateTransformFlagsForSubtree(node);
|
||||
return computeTransformFlagsForNode(node, subtreeFlags);
|
||||
const subtreeFlags = aggregateTransformFlagsForSubtree(node);
|
||||
return computeTransformFlagsForNode(node, subtreeFlags);
|
||||
}
|
||||
|
||||
function aggregateTransformFlagsForNodeArray(nodes: NodeArray<Node>): TransformFlags {
|
||||
if (nodes === undefined) {
|
||||
return TransformFlags.None;
|
||||
}
|
||||
let subtreeFlags = TransformFlags.None;
|
||||
let nodeArrayFlags = TransformFlags.None;
|
||||
for (const node of nodes) {
|
||||
subtreeFlags |= aggregateTransformFlagsForNode(node);
|
||||
nodeArrayFlags |= node.transformFlags & ~TransformFlags.HasComputedFlags;
|
||||
}
|
||||
nodes.transformFlags = nodeArrayFlags | TransformFlags.HasComputedFlags;
|
||||
return subtreeFlags;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1282,15 +1310,19 @@ namespace ts {
|
||||
}
|
||||
|
||||
// Aggregate the transform flags of each child.
|
||||
return reduceEachChild(node, aggregateTransformFlagsForChildNode, TransformFlags.None);
|
||||
return reduceEachChild(node, TransformFlags.None, aggregateTransformFlagsForChildNode, aggregateTransformFlagsForChildNodes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggregates the TransformFlags of a child node with the TransformFlags of its
|
||||
* siblings.
|
||||
*/
|
||||
function aggregateTransformFlagsForChildNode(transformFlags: TransformFlags, child: Node): TransformFlags {
|
||||
return transformFlags | aggregateTransformFlagsForNode(child);
|
||||
function aggregateTransformFlagsForChildNode(transformFlags: TransformFlags, node: Node): TransformFlags {
|
||||
return transformFlags | aggregateTransformFlagsForNode(node);
|
||||
}
|
||||
|
||||
function aggregateTransformFlagsForChildNodes(transformFlags: TransformFlags, nodes: NodeArray<Node>): TransformFlags {
|
||||
return transformFlags | aggregateTransformFlagsForNodeArray(nodes);
|
||||
}
|
||||
|
||||
export namespace Debug {
|
||||
@@ -1302,6 +1334,13 @@ namespace ts {
|
||||
? (node: Node, message?: string) => assert(false, message || "Unexpected node.", () => `Node ${formatSyntaxKind(node.kind)} was unexpected.`)
|
||||
: noop;
|
||||
|
||||
export const assertEachNode = shouldAssert(AssertionLevel.Normal)
|
||||
? (nodes: Node[], test: (node: Node) => boolean, message?: string) => assert(
|
||||
test === undefined || every(nodes, test),
|
||||
message || "Unexpected node.",
|
||||
() => `Node array did not pass test '${getFunctionName(test)}'.`)
|
||||
: noop;
|
||||
|
||||
export const assertNode = shouldAssert(AssertionLevel.Normal)
|
||||
? (node: Node, test: (node: Node) => boolean, message?: string) => assert(
|
||||
test === undefined || test(node),
|
||||
@@ -1309,6 +1348,27 @@ namespace ts {
|
||||
() => `Node ${formatSyntaxKind(node.kind)} did not pass test '${getFunctionName(test)}'.`)
|
||||
: noop;
|
||||
|
||||
export const assertOptionalNode = shouldAssert(AssertionLevel.Normal)
|
||||
? (node: Node, test: (node: Node) => boolean, message?: string) => assert(
|
||||
test === undefined || node === undefined || test(node),
|
||||
message || "Unexpected node.",
|
||||
() => `Node ${formatSyntaxKind(node.kind)} did not pass test '${getFunctionName(test)}'.`)
|
||||
: noop;
|
||||
|
||||
export const assertOptionalToken = shouldAssert(AssertionLevel.Normal)
|
||||
? (node: Node, kind: SyntaxKind, message?: string) => assert(
|
||||
kind === undefined || node === undefined || node.kind === kind,
|
||||
message || "Unexpected node.",
|
||||
() => `Node ${formatSyntaxKind(node.kind)} was not a '${formatSyntaxKind(kind)}' token.`)
|
||||
: noop;
|
||||
|
||||
export const assertMissingNode = shouldAssert(AssertionLevel.Normal)
|
||||
? (node: Node, message?: string) => assert(
|
||||
node === undefined,
|
||||
message || "Unexpected node.",
|
||||
() => `Node ${formatSyntaxKind(node.kind)} was unexpected'.`)
|
||||
: noop;
|
||||
|
||||
function getFunctionName(func: Function) {
|
||||
if (typeof func !== "function") {
|
||||
return "";
|
||||
|
||||
@@ -170,7 +170,7 @@ class CompilerBaselineRunner extends RunnerBase {
|
||||
});
|
||||
|
||||
it("Correct Sourcemap output for " + fileName, () => {
|
||||
Harness.Compiler.doSourcemapBaseline(justName, options, result);
|
||||
Harness.Compiler.doSourcemapBaseline(justName, options, result, harnessSettings);
|
||||
});
|
||||
|
||||
it("Correct type/symbol baselines for " + fileName, () => {
|
||||
|
||||
@@ -2013,13 +2013,13 @@ namespace FourSlash {
|
||||
this.raiseError("Errors expected.");
|
||||
}
|
||||
|
||||
if (diagnostics.length > 1 && errorCode !== undefined) {
|
||||
if (diagnostics.length > 1 && errorCode === undefined) {
|
||||
this.raiseError("When there's more than one error, you must specify the errror to fix.");
|
||||
}
|
||||
|
||||
const diagnostic = !errorCode ? diagnostics[0] : ts.find(diagnostics, d => d.code == errorCode);
|
||||
|
||||
return this.languageService.getCodeFixesAtPosition(fileName, diagnostic.start, diagnostic.length, [diagnostic.code]);
|
||||
return this.languageService.getCodeFixesAtPosition(fileName, diagnostic.start, diagnostic.start + diagnostic.length, [diagnostic.code]);
|
||||
}
|
||||
|
||||
public verifyCodeFixAtPosition(expectedText: string, errorCode?: number) {
|
||||
|
||||
+59
-56
@@ -470,19 +470,6 @@ namespace Utils {
|
||||
}
|
||||
}
|
||||
|
||||
namespace Harness.Path {
|
||||
export function getFileName(fullPath: string) {
|
||||
return fullPath.replace(/^.*[\\\/]/, "");
|
||||
}
|
||||
|
||||
export function filePath(fullPath: string) {
|
||||
fullPath = ts.normalizeSlashes(fullPath);
|
||||
const components = fullPath.split("/");
|
||||
const path: string[] = components.slice(0, components.length - 1);
|
||||
return path.join("/") + "/";
|
||||
}
|
||||
}
|
||||
|
||||
namespace Harness {
|
||||
export interface IO {
|
||||
newLine(): string;
|
||||
@@ -971,28 +958,38 @@ namespace Harness {
|
||||
// Local get canonical file name function, that depends on passed in parameter for useCaseSensitiveFileNames
|
||||
const getCanonicalFileName = ts.createGetCanonicalFileName(useCaseSensitiveFileNames);
|
||||
|
||||
const realPathMap: ts.FileMap<string> = ts.createFileMap<string>();
|
||||
const fileMap: ts.FileMap<() => ts.SourceFile> = ts.createFileMap<() => ts.SourceFile>();
|
||||
/** Maps a symlink name to a realpath. Used only for exposing `realpath`. */
|
||||
const realPathMap = ts.createFileMap<string>();
|
||||
/**
|
||||
* Maps a file name to a source file.
|
||||
* This will have a different SourceFile for every symlink pointing to that file;
|
||||
* if the program resolves realpaths then symlink entries will be ignored.
|
||||
*/
|
||||
const fileMap = ts.createFileMap<ts.SourceFile>();
|
||||
for (const file of inputFiles) {
|
||||
if (file.content !== undefined) {
|
||||
const fileName = ts.normalizePath(file.unitName);
|
||||
const path = ts.toPath(file.unitName, currentDirectory, getCanonicalFileName);
|
||||
if (file.fileOptions && file.fileOptions["symlink"]) {
|
||||
const link = file.fileOptions["symlink"];
|
||||
const linkPath = ts.toPath(link, currentDirectory, getCanonicalFileName);
|
||||
realPathMap.set(linkPath, fileName);
|
||||
fileMap.set(path, (): ts.SourceFile => { throw new Error("Symlinks should always be resolved to a realpath first"); });
|
||||
const links = file.fileOptions["symlink"].split(",");
|
||||
for (const link of links) {
|
||||
const linkPath = ts.toPath(link, currentDirectory, getCanonicalFileName);
|
||||
realPathMap.set(linkPath, fileName);
|
||||
// Create a different SourceFile for every symlink.
|
||||
const sourceFile = createSourceFileAndAssertInvariants(linkPath, file.content, scriptTarget);
|
||||
fileMap.set(linkPath, sourceFile);
|
||||
}
|
||||
}
|
||||
const sourceFile = createSourceFileAndAssertInvariants(fileName, file.content, scriptTarget);
|
||||
fileMap.set(path, () => sourceFile);
|
||||
fileMap.set(path, sourceFile);
|
||||
}
|
||||
}
|
||||
|
||||
function getSourceFile(fileName: string) {
|
||||
fileName = ts.normalizePath(fileName);
|
||||
const path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
|
||||
if (fileMap.contains(path)) {
|
||||
return fileMap.get(path)();
|
||||
const fromFileMap = fileMap.get(toPath(fileName));
|
||||
if (fromFileMap) {
|
||||
return fromFileMap;
|
||||
}
|
||||
else if (fileName === fourslashFileName) {
|
||||
const tsFn = "tests/cases/fourslash/" + fourslashFileName;
|
||||
@@ -1011,6 +1008,9 @@ namespace Harness {
|
||||
newLineKind === ts.NewLineKind.LineFeed ? lineFeed :
|
||||
Harness.IO.newLine();
|
||||
|
||||
function toPath(fileName: string): ts.Path {
|
||||
return ts.toPath(fileName, currentDirectory, getCanonicalFileName);
|
||||
}
|
||||
|
||||
return {
|
||||
getCurrentDirectory: () => currentDirectory,
|
||||
@@ -1020,24 +1020,26 @@ namespace Harness {
|
||||
getCanonicalFileName,
|
||||
useCaseSensitiveFileNames: () => useCaseSensitiveFileNames,
|
||||
getNewLine: () => newLine,
|
||||
fileExists: fileName => {
|
||||
const path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
|
||||
return fileMap.contains(path) || (realPathMap && realPathMap.contains(path));
|
||||
},
|
||||
fileExists: fileName => fileMap.contains(toPath(fileName)),
|
||||
readFile: (fileName: string): string => {
|
||||
return fileMap.get(ts.toPath(fileName, currentDirectory, getCanonicalFileName))().getText();
|
||||
const file = fileMap.get(toPath(fileName));
|
||||
if (ts.endsWith(fileName, "json")) {
|
||||
// strip comments
|
||||
return file.getText();
|
||||
}
|
||||
return file.text;
|
||||
},
|
||||
realpath: (fileName: string): ts.Path => {
|
||||
const path = toPath(fileName);
|
||||
return (realPathMap.get(path) as ts.Path) || path;
|
||||
},
|
||||
realpath: realPathMap && ((f: string) => {
|
||||
const path = ts.toPath(f, currentDirectory, getCanonicalFileName);
|
||||
return realPathMap.get(path) || path;
|
||||
}),
|
||||
directoryExists: dir => {
|
||||
let path = ts.toPath(dir, currentDirectory, getCanonicalFileName);
|
||||
// Strip trailing /, which may exist if the path is a drive root
|
||||
if (path[path.length - 1] === "/") {
|
||||
path = <ts.Path>path.substr(0, path.length - 1);
|
||||
}
|
||||
return mapHasFileInDirectory(path, fileMap) || mapHasFileInDirectory(path, realPathMap);
|
||||
return mapHasFileInDirectory(path, fileMap);
|
||||
},
|
||||
getDirectories: d => {
|
||||
const path = ts.toPath(d, currentDirectory, getCanonicalFileName);
|
||||
@@ -1090,7 +1092,9 @@ namespace Harness {
|
||||
{ name: "suppressOutputPathCheck", type: "boolean" },
|
||||
{ name: "noImplicitReferences", type: "boolean" },
|
||||
{ name: "currentDirectory", type: "string" },
|
||||
{ name: "symlink", type: "string" }
|
||||
{ name: "symlink", type: "string" },
|
||||
// Emitted js baseline will print full paths for every output file
|
||||
{ name: "fullEmitPaths", type: "boolean" }
|
||||
];
|
||||
|
||||
let optionsIndex: ts.Map<ts.CommandLineOption>;
|
||||
@@ -1483,7 +1487,7 @@ namespace Harness {
|
||||
}
|
||||
|
||||
if (typesError && symbolsError) {
|
||||
throw new Error(typesError.message + ts.sys.newLine + symbolsError.message);
|
||||
throw new Error(typesError.message + Harness.IO.newLine() + symbolsError.message);
|
||||
}
|
||||
|
||||
if (typesError) {
|
||||
@@ -1565,7 +1569,7 @@ namespace Harness {
|
||||
return file.writeByteOrderMark ? "\u00EF\u00BB\u00BF" : "";
|
||||
}
|
||||
|
||||
export function doSourcemapBaseline(baselinePath: string, options: ts.CompilerOptions, result: CompilerResult) {
|
||||
export function doSourcemapBaseline(baselinePath: string, options: ts.CompilerOptions, result: CompilerResult, harnessSettings: Harness.TestCaseParser.CompilerSettings) {
|
||||
if (options.inlineSourceMap) {
|
||||
if (result.sourceMaps.length > 0) {
|
||||
throw new Error("No sourcemap files should be generated if inlineSourceMaps was set.");
|
||||
@@ -1587,10 +1591,8 @@ namespace Harness {
|
||||
}
|
||||
|
||||
let sourceMapCode = "";
|
||||
for (let i = 0; i < result.sourceMaps.length; i++) {
|
||||
sourceMapCode += "//// [" + Harness.Path.getFileName(result.sourceMaps[i].fileName) + "]\r\n";
|
||||
sourceMapCode += getByteOrderMarkText(result.sourceMaps[i]);
|
||||
sourceMapCode += result.sourceMaps[i].code;
|
||||
for (const sourceMap of result.sourceMaps) {
|
||||
sourceMapCode += fileOutput(sourceMap, harnessSettings);
|
||||
}
|
||||
|
||||
return sourceMapCode;
|
||||
@@ -1611,23 +1613,19 @@ namespace Harness {
|
||||
tsCode += "//// [" + header + "] ////\r\n\r\n";
|
||||
}
|
||||
for (let i = 0; i < tsSources.length; i++) {
|
||||
tsCode += "//// [" + Harness.Path.getFileName(tsSources[i].unitName) + "]\r\n";
|
||||
tsCode += "//// [" + ts.getBaseFileName(tsSources[i].unitName) + "]\r\n";
|
||||
tsCode += tsSources[i].content + (i < (tsSources.length - 1) ? "\r\n" : "");
|
||||
}
|
||||
|
||||
let jsCode = "";
|
||||
for (let i = 0; i < result.files.length; i++) {
|
||||
jsCode += "//// [" + Harness.Path.getFileName(result.files[i].fileName) + "]\r\n";
|
||||
jsCode += getByteOrderMarkText(result.files[i]);
|
||||
jsCode += result.files[i].code;
|
||||
for (const file of result.files) {
|
||||
jsCode += fileOutput(file, harnessSettings);
|
||||
}
|
||||
|
||||
if (result.declFilesCode.length > 0) {
|
||||
jsCode += "\r\n\r\n";
|
||||
for (let i = 0; i < result.declFilesCode.length; i++) {
|
||||
jsCode += "//// [" + Harness.Path.getFileName(result.declFilesCode[i].fileName) + "]\r\n";
|
||||
jsCode += getByteOrderMarkText(result.declFilesCode[i]);
|
||||
jsCode += result.declFilesCode[i].code;
|
||||
for (const declFile of result.declFilesCode) {
|
||||
jsCode += fileOutput(declFile, harnessSettings);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1652,6 +1650,11 @@ namespace Harness {
|
||||
});
|
||||
}
|
||||
|
||||
function fileOutput(file: GeneratedFile, harnessSettings: Harness.TestCaseParser.CompilerSettings): string {
|
||||
const fileName = harnessSettings["fullEmitPaths"] ? file.fileName : ts.getBaseFileName(file.fileName);
|
||||
return "//// [" + fileName + "]\r\n" + getByteOrderMarkText(file) + file.code;
|
||||
}
|
||||
|
||||
export function collateOutputs(outputFiles: Harness.Compiler.GeneratedFile[]): string {
|
||||
// Collect, test, and sort the fileNames
|
||||
outputFiles.sort((a, b) => ts.compareStrings(cleanName(a.fileName), cleanName(b.fileName)));
|
||||
@@ -1768,7 +1771,7 @@ namespace Harness {
|
||||
}
|
||||
|
||||
// Regex for parsing options in the format "@Alpha: Value of any sort"
|
||||
const optionRegex = /^[\/]{2}\s*@(\w+)\s*:\s*(\S*)/gm; // multiple matches on multiple lines
|
||||
const optionRegex = /^[\/]{2}\s*@(\w+)\s*:\s*([^\r\n]*)/gm; // multiple matches on multiple lines
|
||||
|
||||
function extractCompilerSettings(content: string): CompilerSettings {
|
||||
const opts: CompilerSettings = {};
|
||||
@@ -1777,7 +1780,7 @@ namespace Harness {
|
||||
/* tslint:disable:no-null-keyword */
|
||||
while ((match = optionRegex.exec(content)) !== null) {
|
||||
/* tslint:enable:no-null-keyword */
|
||||
opts[match[1]] = match[2];
|
||||
opts[match[1]] = match[2].trim();
|
||||
}
|
||||
|
||||
return opts;
|
||||
@@ -1805,7 +1808,7 @@ namespace Harness {
|
||||
// Comment line, check for global/file @options and record them
|
||||
optionRegex.lastIndex = 0;
|
||||
const metaDataName = testMetaData[1].toLowerCase();
|
||||
currentFileOptions[testMetaData[1]] = testMetaData[2];
|
||||
currentFileOptions[testMetaData[1]] = testMetaData[2].trim();
|
||||
if (metaDataName !== "filename") {
|
||||
continue;
|
||||
}
|
||||
@@ -1825,12 +1828,12 @@ namespace Harness {
|
||||
// Reset local data
|
||||
currentFileContent = undefined;
|
||||
currentFileOptions = {};
|
||||
currentFileName = testMetaData[2];
|
||||
currentFileName = testMetaData[2].trim();
|
||||
refs = [];
|
||||
}
|
||||
else {
|
||||
// First metadata marker in the file
|
||||
currentFileName = testMetaData[2];
|
||||
currentFileName = testMetaData[2].trim();
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -1848,7 +1851,7 @@ namespace Harness {
|
||||
}
|
||||
|
||||
// normalize the fileName for the single file case
|
||||
currentFileName = testUnitData.length > 0 || currentFileName ? currentFileName : Path.getFileName(fileName);
|
||||
currentFileName = testUnitData.length > 0 || currentFileName ? currentFileName : ts.getBaseFileName(fileName);
|
||||
|
||||
// EOF, push whatever remains
|
||||
const newTestFile2 = {
|
||||
@@ -2012,7 +2015,7 @@ namespace Harness {
|
||||
|
||||
export function isDefaultLibraryFile(filePath: string): boolean {
|
||||
// We need to make sure that the filePath is prefixed with "lib." not just containing "lib." and end with ".d.ts"
|
||||
const fileName = Path.getFileName(filePath);
|
||||
const fileName = ts.getBaseFileName(filePath);
|
||||
return ts.startsWith(fileName, "lib.") && ts.endsWith(fileName, ".d.ts");
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,10 @@ function createRunner(kind: TestRunnerKind): RunnerBase {
|
||||
}
|
||||
}
|
||||
|
||||
if (Harness.IO.tryEnableSourceMapsForHost && /^development$/i.test(Harness.IO.getEnvironmentVariable("NODE_ENV"))) {
|
||||
Harness.IO.tryEnableSourceMapsForHost();
|
||||
}
|
||||
|
||||
// users can define tests to run in mytest.config that will override cmd line args, otherwise use cmd line args (test.config), otherwise no options
|
||||
|
||||
const mytestconfigFileName = "mytest.config";
|
||||
|
||||
@@ -32,7 +32,7 @@ abstract class RunnerBase {
|
||||
/** Replaces instances of full paths with fileNames only */
|
||||
static removeFullPaths(path: string) {
|
||||
// If its a full path (starts with "C:" or "/") replace with just the filename
|
||||
let fixedPath = /^(\w:|\/)/.test(path) ? Harness.Path.getFileName(path) : path;
|
||||
let fixedPath = /^(\w:|\/)/.test(path) ? ts.getBaseFileName(path) : path;
|
||||
|
||||
// when running in the browser the 'full path' is the host name, shows up in error baselines
|
||||
const localHost = /http:\/localhost:\d+/g;
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
"../compiler/visitor.ts",
|
||||
"../compiler/transformers/ts.ts",
|
||||
"../compiler/transformers/jsx.ts",
|
||||
"../compiler/transformers/esnext.ts",
|
||||
"../compiler/transformers/es2017.ts",
|
||||
"../compiler/transformers/es2016.ts",
|
||||
"../compiler/transformers/es2015.ts",
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace ts {
|
||||
assertParseResult(["--lib", "es5,invalidOption", "0.ts"],
|
||||
{
|
||||
errors: [{
|
||||
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'",
|
||||
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string'",
|
||||
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
|
||||
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
|
||||
|
||||
@@ -165,7 +165,7 @@ namespace ts {
|
||||
start: undefined,
|
||||
length: undefined,
|
||||
}, {
|
||||
messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017'",
|
||||
messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017', 'esnext'",
|
||||
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
|
||||
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
|
||||
|
||||
@@ -263,7 +263,7 @@ namespace ts {
|
||||
assertParseResult(["--lib", "es5,", "es7", "0.ts"],
|
||||
{
|
||||
errors: [{
|
||||
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'",
|
||||
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string'",
|
||||
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
|
||||
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
|
||||
|
||||
@@ -283,7 +283,7 @@ namespace ts {
|
||||
assertParseResult(["--lib", "es5, ", "es7", "0.ts"],
|
||||
{
|
||||
errors: [{
|
||||
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'",
|
||||
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string'",
|
||||
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
|
||||
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
|
||||
|
||||
|
||||
@@ -492,5 +492,45 @@ namespace ts.projectSystem {
|
||||
assert.isTrue(host.fileExists(expectedEmittedFileName));
|
||||
assert.equal(host.readFile(expectedEmittedFileName), `"use strict";\r\nfunction Foo() { return 10; }\r\nexports.Foo = Foo;\r\n`);
|
||||
});
|
||||
|
||||
it("shoud not emit js files in external projects", () => {
|
||||
const file1 = {
|
||||
path: "/a/b/file1.ts",
|
||||
content: "consonle.log('file1');"
|
||||
};
|
||||
// file2 has errors. The emitting should not be blocked.
|
||||
const file2 = {
|
||||
path: "/a/b/file2.js",
|
||||
content: "console.log'file2');"
|
||||
};
|
||||
const file3 = {
|
||||
path: "/a/b/file3.js",
|
||||
content: "console.log('file3');"
|
||||
};
|
||||
const externalProjectName = "externalproject";
|
||||
const host = createServerHost([file1, file2, file3, libFile]);
|
||||
const session = createSession(host);
|
||||
const projectService = session.getProjectService();
|
||||
|
||||
projectService.openExternalProject({
|
||||
rootFiles: toExternalFiles([file1.path, file2.path]),
|
||||
options: {
|
||||
allowJs: true,
|
||||
outFile: "dist.js",
|
||||
compileOnSave: true
|
||||
},
|
||||
projectFileName: externalProjectName
|
||||
});
|
||||
|
||||
const emitRequest = makeSessionRequest<server.protocol.CompileOnSaveEmitFileRequestArgs>(CommandNames.CompileOnSaveEmitFile, { file: file1.path });
|
||||
session.executeCommand(emitRequest);
|
||||
|
||||
const expectedOutFileName = "/a/b/dist.js";
|
||||
assert.isTrue(host.fileExists(expectedOutFileName));
|
||||
const outFileContent = host.readFile(expectedOutFileName);
|
||||
assert.isTrue(outFileContent.indexOf(file1.content) !== -1);
|
||||
assert.isTrue(outFileContent.indexOf(file2.content) === -1);
|
||||
assert.isTrue(outFileContent.indexOf(file3.content) === -1);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -176,7 +176,7 @@ namespace ts {
|
||||
file: undefined,
|
||||
start: 0,
|
||||
length: 0,
|
||||
messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017'",
|
||||
messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017', 'esnext'",
|
||||
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
|
||||
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category
|
||||
}]
|
||||
@@ -233,7 +233,7 @@ namespace ts {
|
||||
file: undefined,
|
||||
start: 0,
|
||||
length: 0,
|
||||
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'",
|
||||
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string'",
|
||||
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
|
||||
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category
|
||||
}]
|
||||
@@ -264,7 +264,7 @@ namespace ts {
|
||||
file: undefined,
|
||||
start: 0,
|
||||
length: 0,
|
||||
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'",
|
||||
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string'",
|
||||
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
|
||||
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category
|
||||
}]
|
||||
@@ -295,7 +295,7 @@ namespace ts {
|
||||
file: undefined,
|
||||
start: 0,
|
||||
length: 0,
|
||||
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'",
|
||||
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string'",
|
||||
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
|
||||
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category
|
||||
}]
|
||||
@@ -326,7 +326,7 @@ namespace ts {
|
||||
file: undefined,
|
||||
start: 0,
|
||||
length: 0,
|
||||
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'",
|
||||
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string'",
|
||||
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
|
||||
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category
|
||||
}]
|
||||
|
||||
@@ -197,13 +197,9 @@ namespace ts {
|
||||
"/a/b/c/d/node_modules/foo/index.tsx",
|
||||
"/a/b/c/d/node_modules/foo/index.d.ts",
|
||||
|
||||
"/a/b/c/d/node_modules/@types/foo.ts",
|
||||
"/a/b/c/d/node_modules/@types/foo.tsx",
|
||||
"/a/b/c/d/node_modules/@types/foo.d.ts",
|
||||
"/a/b/c/d/node_modules/@types/foo/package.json",
|
||||
|
||||
"/a/b/c/d/node_modules/@types/foo/index.ts",
|
||||
"/a/b/c/d/node_modules/@types/foo/index.tsx",
|
||||
"/a/b/c/d/node_modules/@types/foo/index.d.ts",
|
||||
|
||||
"/a/b/c/node_modules/foo.ts",
|
||||
@@ -215,13 +211,9 @@ namespace ts {
|
||||
"/a/b/c/node_modules/foo/index.tsx",
|
||||
"/a/b/c/node_modules/foo/index.d.ts",
|
||||
|
||||
"/a/b/c/node_modules/@types/foo.ts",
|
||||
"/a/b/c/node_modules/@types/foo.tsx",
|
||||
"/a/b/c/node_modules/@types/foo.d.ts",
|
||||
"/a/b/c/node_modules/@types/foo/package.json",
|
||||
|
||||
"/a/b/c/node_modules/@types/foo/index.ts",
|
||||
"/a/b/c/node_modules/@types/foo/index.tsx",
|
||||
"/a/b/c/node_modules/@types/foo/index.d.ts",
|
||||
]);
|
||||
}
|
||||
@@ -257,13 +249,9 @@ namespace ts {
|
||||
"/a/node_modules/b/c/node_modules/d/node_modules/foo/index.tsx",
|
||||
"/a/node_modules/b/c/node_modules/d/node_modules/foo/index.d.ts",
|
||||
|
||||
"/a/node_modules/b/c/node_modules/d/node_modules/@types/foo.ts",
|
||||
"/a/node_modules/b/c/node_modules/d/node_modules/@types/foo.tsx",
|
||||
"/a/node_modules/b/c/node_modules/d/node_modules/@types/foo.d.ts",
|
||||
"/a/node_modules/b/c/node_modules/d/node_modules/@types/foo/package.json",
|
||||
|
||||
"/a/node_modules/b/c/node_modules/d/node_modules/@types/foo/index.ts",
|
||||
"/a/node_modules/b/c/node_modules/d/node_modules/@types/foo/index.tsx",
|
||||
"/a/node_modules/b/c/node_modules/d/node_modules/@types/foo/index.d.ts",
|
||||
|
||||
"/a/node_modules/b/c/node_modules/foo.ts",
|
||||
@@ -275,13 +263,9 @@ namespace ts {
|
||||
"/a/node_modules/b/c/node_modules/foo/index.tsx",
|
||||
"/a/node_modules/b/c/node_modules/foo/index.d.ts",
|
||||
|
||||
"/a/node_modules/b/c/node_modules/@types/foo.ts",
|
||||
"/a/node_modules/b/c/node_modules/@types/foo.tsx",
|
||||
"/a/node_modules/b/c/node_modules/@types/foo.d.ts",
|
||||
"/a/node_modules/b/c/node_modules/@types/foo/package.json",
|
||||
|
||||
"/a/node_modules/b/c/node_modules/@types/foo/index.ts",
|
||||
"/a/node_modules/b/c/node_modules/@types/foo/index.tsx",
|
||||
"/a/node_modules/b/c/node_modules/@types/foo/index.d.ts",
|
||||
|
||||
"/a/node_modules/b/node_modules/foo.ts",
|
||||
@@ -293,13 +277,9 @@ namespace ts {
|
||||
"/a/node_modules/b/node_modules/foo/index.tsx",
|
||||
"/a/node_modules/b/node_modules/foo/index.d.ts",
|
||||
|
||||
"/a/node_modules/b/node_modules/@types/foo.ts",
|
||||
"/a/node_modules/b/node_modules/@types/foo.tsx",
|
||||
"/a/node_modules/b/node_modules/@types/foo.d.ts",
|
||||
"/a/node_modules/b/node_modules/@types/foo/package.json",
|
||||
|
||||
"/a/node_modules/b/node_modules/@types/foo/index.ts",
|
||||
"/a/node_modules/b/node_modules/@types/foo/index.tsx",
|
||||
"/a/node_modules/b/node_modules/@types/foo/index.d.ts",
|
||||
|
||||
"/a/node_modules/foo.ts",
|
||||
@@ -709,13 +689,9 @@ import b = require("./moduleB");
|
||||
"/root/folder1/node_modules/file6/index.tsx",
|
||||
"/root/folder1/node_modules/file6/index.d.ts",
|
||||
|
||||
"/root/folder1/node_modules/@types/file6.ts",
|
||||
"/root/folder1/node_modules/@types/file6.tsx",
|
||||
"/root/folder1/node_modules/@types/file6.d.ts",
|
||||
|
||||
"/root/folder1/node_modules/@types/file6/package.json",
|
||||
"/root/folder1/node_modules/@types/file6/index.ts",
|
||||
"/root/folder1/node_modules/@types/file6/index.tsx",
|
||||
"/root/folder1/node_modules/@types/file6/index.d.ts",
|
||||
// success on /root/node_modules/file6.ts
|
||||
], /*isExternalLibraryImport*/ true);
|
||||
|
||||
@@ -394,26 +394,14 @@ namespace ts {
|
||||
"File '/fs.ts' does not exist.",
|
||||
"File '/fs.tsx' does not exist.",
|
||||
"File '/fs.d.ts' does not exist.",
|
||||
"File '/a/b/node_modules/@types/fs.ts' does not exist.",
|
||||
"File '/a/b/node_modules/@types/fs.tsx' does not exist.",
|
||||
"File '/a/b/node_modules/@types/fs.d.ts' does not exist.",
|
||||
"File '/a/b/node_modules/@types/fs/package.json' does not exist.",
|
||||
"File '/a/b/node_modules/@types/fs/index.ts' does not exist.",
|
||||
"File '/a/b/node_modules/@types/fs/index.tsx' does not exist.",
|
||||
"File '/a/b/node_modules/@types/fs/index.d.ts' does not exist.",
|
||||
"File '/a/node_modules/@types/fs.ts' does not exist.",
|
||||
"File '/a/node_modules/@types/fs.tsx' does not exist.",
|
||||
"File '/a/node_modules/@types/fs.d.ts' does not exist.",
|
||||
"File '/a/node_modules/@types/fs/package.json' does not exist.",
|
||||
"File '/a/node_modules/@types/fs/index.ts' does not exist.",
|
||||
"File '/a/node_modules/@types/fs/index.tsx' does not exist.",
|
||||
"File '/a/node_modules/@types/fs/index.d.ts' does not exist.",
|
||||
"File '/node_modules/@types/fs.ts' does not exist.",
|
||||
"File '/node_modules/@types/fs.tsx' does not exist.",
|
||||
"File '/node_modules/@types/fs.d.ts' does not exist.",
|
||||
"File '/node_modules/@types/fs/package.json' does not exist.",
|
||||
"File '/node_modules/@types/fs/index.ts' does not exist.",
|
||||
"File '/node_modules/@types/fs/index.tsx' does not exist.",
|
||||
"File '/node_modules/@types/fs/index.d.ts' does not exist.",
|
||||
"File '/a/b/fs.js' does not exist.",
|
||||
"File '/a/b/fs.jsx' does not exist.",
|
||||
@@ -448,26 +436,14 @@ namespace ts {
|
||||
"File '/fs.ts' does not exist.",
|
||||
"File '/fs.tsx' does not exist.",
|
||||
"File '/fs.d.ts' does not exist.",
|
||||
"File '/a/b/node_modules/@types/fs.ts' does not exist.",
|
||||
"File '/a/b/node_modules/@types/fs.tsx' does not exist.",
|
||||
"File '/a/b/node_modules/@types/fs.d.ts' does not exist.",
|
||||
"File '/a/b/node_modules/@types/fs/package.json' does not exist.",
|
||||
"File '/a/b/node_modules/@types/fs/index.ts' does not exist.",
|
||||
"File '/a/b/node_modules/@types/fs/index.tsx' does not exist.",
|
||||
"File '/a/b/node_modules/@types/fs/index.d.ts' does not exist.",
|
||||
"File '/a/node_modules/@types/fs.ts' does not exist.",
|
||||
"File '/a/node_modules/@types/fs.tsx' does not exist.",
|
||||
"File '/a/node_modules/@types/fs.d.ts' does not exist.",
|
||||
"File '/a/node_modules/@types/fs/package.json' does not exist.",
|
||||
"File '/a/node_modules/@types/fs/index.ts' does not exist.",
|
||||
"File '/a/node_modules/@types/fs/index.tsx' does not exist.",
|
||||
"File '/a/node_modules/@types/fs/index.d.ts' does not exist.",
|
||||
"File '/node_modules/@types/fs.ts' does not exist.",
|
||||
"File '/node_modules/@types/fs.tsx' does not exist.",
|
||||
"File '/node_modules/@types/fs.d.ts' does not exist.",
|
||||
"File '/node_modules/@types/fs/package.json' does not exist.",
|
||||
"File '/node_modules/@types/fs/index.ts' does not exist.",
|
||||
"File '/node_modules/@types/fs/index.tsx' does not exist.",
|
||||
"File '/node_modules/@types/fs/index.d.ts' does not exist.",
|
||||
"File '/a/b/fs.js' does not exist.",
|
||||
"File '/a/b/fs.jsx' does not exist.",
|
||||
|
||||
@@ -385,6 +385,10 @@ var x = 0;`, {
|
||||
options: { compilerOptions: { reactNamespace: "react" }, fileName: "input.js", reportDiagnostics: true }
|
||||
});
|
||||
|
||||
transpilesCorrectly("Supports setting 'jsxFactory'", "x;", {
|
||||
options: { compilerOptions: { jsxFactory: "createElement" }, fileName: "input.js", reportDiagnostics: true }
|
||||
});
|
||||
|
||||
transpilesCorrectly("Supports setting 'removeComments'", "x;", {
|
||||
options: { compilerOptions: { removeComments: true }, fileName: "input.js", reportDiagnostics: true }
|
||||
});
|
||||
|
||||
@@ -154,7 +154,6 @@ namespace ts.projectSystem {
|
||||
params.executingFilePath || getExecutingFilePathFromLibFile(),
|
||||
params.currentDirectory || "/",
|
||||
fileOrFolderList);
|
||||
host.createFileOrFolder(safeList, /*createParentDirectory*/ true);
|
||||
return host;
|
||||
}
|
||||
|
||||
@@ -355,7 +354,8 @@ namespace ts.projectSystem {
|
||||
reloadFS(filesOrFolders: FileOrFolder[]) {
|
||||
this.filesOrFolders = filesOrFolders;
|
||||
this.fs = createFileMap<FSEntry>();
|
||||
for (const fileOrFolder of filesOrFolders) {
|
||||
// always inject safelist file in the list of files
|
||||
for (const fileOrFolder of filesOrFolders.concat(safeList)) {
|
||||
const path = this.toPath(fileOrFolder.path);
|
||||
const fullPath = getNormalizedAbsolutePath(fileOrFolder.path, this.currentDirectory);
|
||||
if (typeof fileOrFolder.content === "string") {
|
||||
@@ -1585,6 +1585,104 @@ namespace ts.projectSystem {
|
||||
projectService.closeClientFile(file1.path);
|
||||
checkNumberOfProjects(projectService, { configuredProjects: 0 });
|
||||
});
|
||||
|
||||
it("language service disabled events are triggered", () => {
|
||||
const f1 = {
|
||||
path: "/a/app.js",
|
||||
content: "let x = 1;"
|
||||
};
|
||||
const f2 = {
|
||||
path: "/a/largefile.js",
|
||||
content: ""
|
||||
};
|
||||
const config = {
|
||||
path: "/a/jsconfig.json",
|
||||
content: "{}"
|
||||
};
|
||||
const configWithExclude = {
|
||||
path: config.path,
|
||||
content: JSON.stringify({ exclude: ["largefile.js"] })
|
||||
};
|
||||
const host = createServerHost([f1, f2, config]);
|
||||
const originalGetFileSize = host.getFileSize;
|
||||
host.getFileSize = (filePath: string) =>
|
||||
filePath === f2.path ? server.maxProgramSizeForNonTsFiles + 1 : originalGetFileSize.call(host, filePath);
|
||||
|
||||
let lastEvent: server.ProjectLanguageServiceStateEvent;
|
||||
const session = createSession(host, /*typingsInstaller*/ undefined, e => {
|
||||
if (e.eventName === server.ConfigFileDiagEvent || e.eventName === server.ContextEvent) {
|
||||
return;
|
||||
}
|
||||
assert.equal(e.eventName, server.ProjectLanguageServiceStateEvent);
|
||||
lastEvent = <server.ProjectLanguageServiceStateEvent>e;
|
||||
});
|
||||
session.executeCommand(<protocol.OpenRequest>{
|
||||
seq: 0,
|
||||
type: "request",
|
||||
command: "open",
|
||||
arguments: { file: f1.path }
|
||||
});
|
||||
const projectService = session.getProjectService();
|
||||
checkNumberOfProjects(projectService, { configuredProjects: 1 });
|
||||
const project = projectService.configuredProjects[0];
|
||||
assert.isFalse(project.languageServiceEnabled, "Language service enabled");
|
||||
assert.isTrue(!!lastEvent, "should receive event");
|
||||
assert.equal(lastEvent.data.project, project, "project name");
|
||||
assert.isFalse(lastEvent.data.languageServiceEnabled, "Language service state");
|
||||
|
||||
host.reloadFS([f1, f2, configWithExclude]);
|
||||
host.triggerFileWatcherCallback(config.path, /*removed*/ false);
|
||||
|
||||
checkNumberOfProjects(projectService, { configuredProjects: 1 });
|
||||
assert.isTrue(project.languageServiceEnabled, "Language service enabled");
|
||||
assert.equal(lastEvent.data.project, project, "project");
|
||||
assert.isTrue(lastEvent.data.languageServiceEnabled, "Language service state");
|
||||
});
|
||||
|
||||
it("syntactic features work even if language service is disabled", () => {
|
||||
const f1 = {
|
||||
path: "/a/app.js",
|
||||
content: "let x = 1;"
|
||||
};
|
||||
const f2 = {
|
||||
path: "/a/largefile.js",
|
||||
content: ""
|
||||
};
|
||||
const config = {
|
||||
path: "/a/jsconfig.json",
|
||||
content: "{}"
|
||||
};
|
||||
const host = createServerHost([f1, f2, config]);
|
||||
const originalGetFileSize = host.getFileSize;
|
||||
host.getFileSize = (filePath: string) =>
|
||||
filePath === f2.path ? server.maxProgramSizeForNonTsFiles + 1 : originalGetFileSize.call(host, filePath);
|
||||
let lastEvent: server.ProjectLanguageServiceStateEvent;
|
||||
const session = createSession(host, /*typingsInstaller*/ undefined, e => {
|
||||
if (e.eventName === server.ConfigFileDiagEvent) {
|
||||
return;
|
||||
}
|
||||
assert.equal(e.eventName, server.ProjectLanguageServiceStateEvent);
|
||||
lastEvent = <server.ProjectLanguageServiceStateEvent>e;
|
||||
});
|
||||
session.executeCommand(<protocol.OpenRequest>{
|
||||
seq: 0,
|
||||
type: "request",
|
||||
command: "open",
|
||||
arguments: { file: f1.path }
|
||||
});
|
||||
|
||||
const projectService = session.getProjectService();
|
||||
checkNumberOfProjects(projectService, { configuredProjects: 1 });
|
||||
const project = projectService.configuredProjects[0];
|
||||
assert.isFalse(project.languageServiceEnabled, "Language service enabled");
|
||||
assert.isTrue(!!lastEvent, "should receive event");
|
||||
assert.equal(lastEvent.data.project, project, "project name");
|
||||
assert.isFalse(lastEvent.data.languageServiceEnabled, "Language service state");
|
||||
|
||||
const options = projectService.getFormatCodeOptions();
|
||||
const edits = project.getLanguageService().getFormattingEditsForDocument(f1.path, options);
|
||||
assert.deepEqual(edits, [{ span: createTextSpan(/*start*/ 7, /*length*/ 3), newText: " " }]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Proper errors", () => {
|
||||
@@ -1662,12 +1760,8 @@ namespace ts.projectSystem {
|
||||
"File '/a/b/node_modules/lib/index.ts' does not exist.",
|
||||
"File '/a/b/node_modules/lib/index.tsx' does not exist.",
|
||||
"File '/a/b/node_modules/lib/index.d.ts' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib.ts' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib.tsx' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib.d.ts' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib/package.json' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib/index.ts' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib/index.tsx' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib/index.d.ts' does not exist.",
|
||||
"File '/a/node_modules/lib.ts' does not exist.",
|
||||
"File '/a/node_modules/lib.tsx' does not exist.",
|
||||
@@ -1676,12 +1770,8 @@ namespace ts.projectSystem {
|
||||
"File '/a/node_modules/lib/index.ts' does not exist.",
|
||||
"File '/a/node_modules/lib/index.tsx' does not exist.",
|
||||
"File '/a/node_modules/lib/index.d.ts' does not exist.",
|
||||
"File '/a/node_modules/@types/lib.ts' does not exist.",
|
||||
"File '/a/node_modules/@types/lib.tsx' does not exist.",
|
||||
"File '/a/node_modules/@types/lib.d.ts' does not exist.",
|
||||
"File '/a/node_modules/@types/lib/package.json' does not exist.",
|
||||
"File '/a/node_modules/@types/lib/index.ts' does not exist.",
|
||||
"File '/a/node_modules/@types/lib/index.tsx' does not exist.",
|
||||
"File '/a/node_modules/@types/lib/index.d.ts' does not exist.",
|
||||
"File '/node_modules/lib.ts' does not exist.",
|
||||
"File '/node_modules/lib.tsx' does not exist.",
|
||||
@@ -1690,12 +1780,8 @@ namespace ts.projectSystem {
|
||||
"File '/node_modules/lib/index.ts' does not exist.",
|
||||
"File '/node_modules/lib/index.tsx' does not exist.",
|
||||
"File '/node_modules/lib/index.d.ts' does not exist.",
|
||||
"File '/node_modules/@types/lib.ts' does not exist.",
|
||||
"File '/node_modules/@types/lib.tsx' does not exist.",
|
||||
"File '/node_modules/@types/lib.d.ts' does not exist.",
|
||||
"File '/node_modules/@types/lib/package.json' does not exist.",
|
||||
"File '/node_modules/@types/lib/index.ts' does not exist.",
|
||||
"File '/node_modules/@types/lib/index.tsx' does not exist.",
|
||||
"File '/node_modules/@types/lib/index.d.ts' does not exist.",
|
||||
"Loading module 'lib' from 'node_modules' folder.",
|
||||
"File '/a/b/node_modules/lib.js' does not exist.",
|
||||
@@ -1703,46 +1789,23 @@ namespace ts.projectSystem {
|
||||
"File '/a/b/node_modules/lib/package.json' does not exist.",
|
||||
"File '/a/b/node_modules/lib/index.js' does not exist.",
|
||||
"File '/a/b/node_modules/lib/index.jsx' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib.js' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib.jsx' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib/package.json' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib/index.js' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib/index.jsx' does not exist.",
|
||||
"File '/a/node_modules/lib.js' does not exist.",
|
||||
"File '/a/node_modules/lib.jsx' does not exist.",
|
||||
"File '/a/node_modules/lib/package.json' does not exist.",
|
||||
"File '/a/node_modules/lib/index.js' does not exist.",
|
||||
"File '/a/node_modules/lib/index.jsx' does not exist.",
|
||||
"File '/a/node_modules/@types/lib.js' does not exist.",
|
||||
"File '/a/node_modules/@types/lib.jsx' does not exist.",
|
||||
"File '/a/node_modules/@types/lib/package.json' does not exist.",
|
||||
"File '/a/node_modules/@types/lib/index.js' does not exist.",
|
||||
"File '/a/node_modules/@types/lib/index.jsx' does not exist.",
|
||||
"File '/node_modules/lib.js' does not exist.",
|
||||
"File '/node_modules/lib.jsx' does not exist.",
|
||||
"File '/node_modules/lib/package.json' does not exist.",
|
||||
"File '/node_modules/lib/index.js' does not exist.",
|
||||
"File '/node_modules/lib/index.jsx' does not exist.",
|
||||
"File '/node_modules/@types/lib.js' does not exist.",
|
||||
"File '/node_modules/@types/lib.jsx' does not exist.",
|
||||
"File '/node_modules/@types/lib/package.json' does not exist.",
|
||||
"File '/node_modules/@types/lib/index.js' does not exist.",
|
||||
"File '/node_modules/@types/lib/index.jsx' does not exist.",
|
||||
"======== Module name 'lib' was not resolved. ========",
|
||||
`Auto discovery for typings is enabled in project '${proj.getProjectName()}'. Running extra resolution pass for module 'lib' using cache location '/a/cache'.`,
|
||||
"File '/a/cache/node_modules/lib.ts' does not exist.",
|
||||
"File '/a/cache/node_modules/lib.tsx' does not exist.",
|
||||
"File '/a/cache/node_modules/lib.d.ts' does not exist.",
|
||||
"File '/a/cache/node_modules/lib/package.json' does not exist.",
|
||||
"File '/a/cache/node_modules/lib/index.ts' does not exist.",
|
||||
"File '/a/cache/node_modules/lib/index.tsx' does not exist.",
|
||||
"File '/a/cache/node_modules/lib/index.d.ts' does not exist.",
|
||||
"File '/a/cache/node_modules/@types/lib.ts' does not exist.",
|
||||
"File '/a/cache/node_modules/@types/lib.tsx' does not exist.",
|
||||
"File '/a/cache/node_modules/@types/lib.d.ts' does not exist.",
|
||||
"File '/a/cache/node_modules/@types/lib/package.json' does not exist.",
|
||||
"File '/a/cache/node_modules/@types/lib/index.ts' does not exist.",
|
||||
"File '/a/cache/node_modules/@types/lib/index.tsx' does not exist.",
|
||||
"File '/a/cache/node_modules/@types/lib/index.d.ts' exist - use it as a name resolution result.",
|
||||
]);
|
||||
checkProjectActualFiles(proj, [file1.path, lib.path]);
|
||||
@@ -2576,4 +2639,21 @@ namespace ts.projectSystem {
|
||||
assert.isTrue(diags.length === 0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("import helpers", () => {
|
||||
it("should not crash in tsserver", () => {
|
||||
const f1 = {
|
||||
path: "/a/app.ts",
|
||||
content: "export async function foo() { return 100; }"
|
||||
};
|
||||
const tslib = {
|
||||
path: "/a/node_modules/tslib/index.d.ts",
|
||||
content: ""
|
||||
};
|
||||
const host = createServerHost([f1, tslib]);
|
||||
const service = createProjectService(host);
|
||||
service.openExternalProject({ projectFileName: "p", rootFiles: [toExternalFile(f1.path)], options: { importHelpers: true } });
|
||||
service.checkNumberOfProjects({ externalProjects: 1 });
|
||||
});
|
||||
});
|
||||
}
|
||||
Vendored
+3
-3
@@ -1,5 +1,5 @@
|
||||
interface ProxyHandler<T> {
|
||||
getPrototypeOf? (target: T): any;
|
||||
getPrototypeOf? (target: T): {} | null;
|
||||
setPrototypeOf? (target: T, v: any): boolean;
|
||||
isExtensible? (target: T): boolean;
|
||||
preventExtensions? (target: T): boolean;
|
||||
@@ -12,11 +12,11 @@ interface ProxyHandler<T> {
|
||||
enumerate? (target: T): PropertyKey[];
|
||||
ownKeys? (target: T): PropertyKey[];
|
||||
apply? (target: T, thisArg: any, argArray?: any): any;
|
||||
construct? (target: T, thisArg: any, argArray?: any): any;
|
||||
construct? (target: T, argArray: any, newTarget?: any): {};
|
||||
}
|
||||
|
||||
interface ProxyConstructor {
|
||||
revocable<T>(target: T, handler: ProxyHandler<T>): { proxy: T; revoke: () => void; };
|
||||
new <T>(target: T, handler: ProxyHandler<T>): T
|
||||
}
|
||||
declare var Proxy: ProxyConstructor;
|
||||
declare var Proxy: ProxyConstructor;
|
||||
|
||||
Vendored
+2
-1
@@ -1,3 +1,4 @@
|
||||
/// <reference path="lib.es2016.d.ts" />
|
||||
/// <reference path="lib.es2017.object.d.ts" />
|
||||
/// <reference path="lib.es2017.sharedmemory.d.ts" />
|
||||
/// <reference path="lib.es2017.sharedmemory.d.ts" />
|
||||
/// <reference path="lib.es2017.string.d.ts" />
|
||||
|
||||
Vendored
+2
-2
@@ -9,6 +9,6 @@ interface ObjectConstructor {
|
||||
* Returns an array of key/values of the enumerable properties of an object
|
||||
* @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
|
||||
*/
|
||||
entries<T>(o: { [s: string]: T }): [string, T][];
|
||||
entries<T extends { [key: string]: any }, K extends keyof T>(o: T): [keyof T, T[K]][];
|
||||
entries(o: any): [string, any][];
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
interface String {
|
||||
/**
|
||||
* Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length.
|
||||
* The padding is applied from the start (left) of the current string.
|
||||
*
|
||||
* @param maxLength The length of the resulting string once the current string has been padded.
|
||||
* If this parameter is smaller than the current string's length, the current string will be returned as it is.
|
||||
*
|
||||
* @param fillString The string to pad the current string with.
|
||||
* If this string is too long, it will be truncated and the left-most part will be applied.
|
||||
* The default value for this parameter is " " (U+0020).
|
||||
*/
|
||||
padStart(maxLength: number, fillString?: string): string;
|
||||
|
||||
/**
|
||||
* Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length.
|
||||
* The padding is applied from the end (right) of the current string.
|
||||
*
|
||||
* @param maxLength The length of the resulting string once the current string has been padded.
|
||||
* If this parameter is smaller than the current string's length, the current string will be returned as it is.
|
||||
*
|
||||
* @param fillString The string to pad the current string with.
|
||||
* If this string is too long, it will be truncated and the left-most part will be applied.
|
||||
* The default value for this parameter is " " (U+0020).
|
||||
*/
|
||||
padEnd(maxLength: number, fillString?: string): string;
|
||||
}
|
||||
Vendored
+29
-1
@@ -180,7 +180,7 @@ interface ObjectConstructor {
|
||||
* Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
|
||||
* @param o Object on which to lock the attributes.
|
||||
*/
|
||||
freeze<T>(o: T): T;
|
||||
freeze<T>(o: T): Readonly<T>;
|
||||
|
||||
/**
|
||||
* Prevents the addition of new properties to an object.
|
||||
@@ -1376,6 +1376,34 @@ interface ArrayLike<T> {
|
||||
readonly [n: number]: T;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make all properties in T optional
|
||||
*/
|
||||
type Partial<T> = {
|
||||
[P in keyof T]?: T[P];
|
||||
};
|
||||
|
||||
/**
|
||||
* Make all properties in T readonly
|
||||
*/
|
||||
type Readonly<T> = {
|
||||
readonly [P in keyof T]: T[P];
|
||||
};
|
||||
|
||||
/**
|
||||
* From T pick a set of properties K
|
||||
*/
|
||||
type Pick<T, K extends keyof T> = {
|
||||
[P in K]: T[P];
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a type with a set of properties K of type T
|
||||
*/
|
||||
type Record<K extends string | number, T> = {
|
||||
[P in K]: T;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a raw buffer of binary data, which is used to store data for the
|
||||
* different typed arrays. ArrayBuffers cannot be read from or written to directly,
|
||||
|
||||
@@ -10,8 +10,26 @@
|
||||
namespace ts.server {
|
||||
export const maxProgramSizeForNonTsFiles = 20 * 1024 * 1024;
|
||||
|
||||
export type ProjectServiceEvent =
|
||||
{ eventName: "context", data: { project: Project, fileName: NormalizedPath } } | { eventName: "configFileDiag", data: { triggerFile: string, configFileName: string, diagnostics: Diagnostic[] } };
|
||||
export const ContextEvent = "context";
|
||||
export const ConfigFileDiagEvent = "configFileDiag";
|
||||
export const ProjectLanguageServiceStateEvent = "projectLanguageServiceState";
|
||||
|
||||
export interface ContextEvent {
|
||||
eventName: typeof ContextEvent;
|
||||
data: { project: Project; fileName: NormalizedPath };
|
||||
}
|
||||
|
||||
export interface ConfigFileDiagEvent {
|
||||
eventName: typeof ConfigFileDiagEvent;
|
||||
data: { triggerFile: string, configFileName: string, diagnostics: Diagnostic[] };
|
||||
}
|
||||
|
||||
export interface ProjectLanguageServiceStateEvent {
|
||||
eventName: typeof ProjectLanguageServiceStateEvent;
|
||||
data: { project: Project, languageServiceEnabled: boolean };
|
||||
}
|
||||
|
||||
export type ProjectServiceEvent = ContextEvent | ConfigFileDiagEvent | ProjectLanguageServiceStateEvent;
|
||||
|
||||
export interface ProjectServiceEventHandler {
|
||||
(event: ProjectServiceEvent): void;
|
||||
@@ -282,6 +300,16 @@ namespace ts.server {
|
||||
return this.compilerOptionsForInferredProjects;
|
||||
}
|
||||
|
||||
onUpdateLanguageServiceStateForProject(project: Project, languageServiceEnabled: boolean) {
|
||||
if (!this.eventHandler) {
|
||||
return;
|
||||
}
|
||||
this.eventHandler(<ProjectLanguageServiceStateEvent>{
|
||||
eventName: ProjectLanguageServiceStateEvent,
|
||||
data: { project, languageServiceEnabled }
|
||||
});
|
||||
}
|
||||
|
||||
updateTypingsForProject(response: SetTypings | InvalidateCachedTypings): void {
|
||||
const project = this.findProject(response.projectName);
|
||||
if (!project) {
|
||||
@@ -430,7 +458,10 @@ namespace ts.server {
|
||||
}
|
||||
|
||||
for (const openFile of this.openFiles) {
|
||||
this.eventHandler({ eventName: "context", data: { project: openFile.getDefaultProject(), fileName: openFile.fileName } });
|
||||
this.eventHandler(<ContextEvent>{
|
||||
eventName: ContextEvent,
|
||||
data: { project: openFile.getDefaultProject(), fileName: openFile.fileName }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -834,8 +865,8 @@ namespace ts.server {
|
||||
return;
|
||||
}
|
||||
|
||||
this.eventHandler({
|
||||
eventName: "configFileDiag",
|
||||
this.eventHandler(<ConfigFileDiagEvent>{
|
||||
eventName: ConfigFileDiagEvent,
|
||||
data: { configFileName, diagnostics: diagnostics || [], triggerFile }
|
||||
});
|
||||
}
|
||||
@@ -1013,7 +1044,7 @@ namespace ts.server {
|
||||
const useExistingProject = this.useSingleInferredProject && this.inferredProjects.length;
|
||||
const project = useExistingProject
|
||||
? this.inferredProjects[0]
|
||||
: new InferredProject(this, this.documentRegistry, /*languageServiceEnabled*/ true, this.compilerOptionsForInferredProjects);
|
||||
: new InferredProject(this, this.documentRegistry, this.compilerOptionsForInferredProjects);
|
||||
|
||||
project.addRoot(root);
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
/// <reference path="scriptInfo.ts" />
|
||||
|
||||
namespace ts.server {
|
||||
export class LSHost implements ts.LanguageServiceHost, ModuleResolutionHost, ServerLanguageServiceHost {
|
||||
export class LSHost implements ts.LanguageServiceHost, ModuleResolutionHost {
|
||||
private compilationSettings: ts.CompilerOptions;
|
||||
private readonly resolvedModuleNames= createFileMap<Map<ResolvedModuleWithFailedLookupLocations>>();
|
||||
private readonly resolvedModuleNames = createFileMap<Map<ResolvedModuleWithFailedLookupLocations>>();
|
||||
private readonly resolvedTypeReferenceDirectives = createFileMap<Map<ResolvedTypeReferenceDirectiveWithFailedLookupLocations>>();
|
||||
private readonly getCanonicalFileName: (fileName: string) => string;
|
||||
|
||||
|
||||
+112
-19
@@ -90,16 +90,102 @@ namespace ts.server {
|
||||
}
|
||||
}
|
||||
|
||||
const emptyResult: any[] = [];
|
||||
const getEmptyResult = () => emptyResult;
|
||||
const getUndefined = () => <any>undefined;
|
||||
const emptyEncodedSemanticClassifications = { spans: emptyResult, endOfLineState: EndOfLineState.None };
|
||||
|
||||
export function createNoSemanticFeaturesWrapper(realLanguageService: LanguageService): LanguageService {
|
||||
return {
|
||||
cleanupSemanticCache: noop,
|
||||
getSyntacticDiagnostics: (fileName) =>
|
||||
fileName ? realLanguageService.getSyntacticDiagnostics(fileName) : emptyResult,
|
||||
getSemanticDiagnostics: getEmptyResult,
|
||||
getCompilerOptionsDiagnostics: () =>
|
||||
realLanguageService.getCompilerOptionsDiagnostics(),
|
||||
getSyntacticClassifications: (fileName, span) =>
|
||||
realLanguageService.getSyntacticClassifications(fileName, span),
|
||||
getEncodedSyntacticClassifications: (fileName, span) =>
|
||||
realLanguageService.getEncodedSyntacticClassifications(fileName, span),
|
||||
getSemanticClassifications: getEmptyResult,
|
||||
getEncodedSemanticClassifications: () =>
|
||||
emptyEncodedSemanticClassifications,
|
||||
getCompletionsAtPosition: getUndefined,
|
||||
findReferences: getEmptyResult,
|
||||
getCompletionEntryDetails: getUndefined,
|
||||
getQuickInfoAtPosition: getUndefined,
|
||||
findRenameLocations: getEmptyResult,
|
||||
getNameOrDottedNameSpan: (fileName, startPos, endPos) =>
|
||||
realLanguageService.getNameOrDottedNameSpan(fileName, startPos, endPos),
|
||||
getBreakpointStatementAtPosition: (fileName, position) =>
|
||||
realLanguageService.getBreakpointStatementAtPosition(fileName, position),
|
||||
getBraceMatchingAtPosition: (fileName, position) =>
|
||||
realLanguageService.getBraceMatchingAtPosition(fileName, position),
|
||||
getSignatureHelpItems: getUndefined,
|
||||
getDefinitionAtPosition: getEmptyResult,
|
||||
getRenameInfo: () => ({
|
||||
canRename: false,
|
||||
localizedErrorMessage: getLocaleSpecificMessage(Diagnostics.Language_service_is_disabled),
|
||||
displayName: undefined,
|
||||
fullDisplayName: undefined,
|
||||
kind: undefined,
|
||||
kindModifiers: undefined,
|
||||
triggerSpan: undefined
|
||||
}),
|
||||
getTypeDefinitionAtPosition: getUndefined,
|
||||
getReferencesAtPosition: getEmptyResult,
|
||||
getDocumentHighlights: getEmptyResult,
|
||||
getOccurrencesAtPosition: getEmptyResult,
|
||||
getNavigateToItems: getEmptyResult,
|
||||
getNavigationBarItems: fileName =>
|
||||
realLanguageService.getNavigationBarItems(fileName),
|
||||
getNavigationTree: fileName =>
|
||||
realLanguageService.getNavigationTree(fileName),
|
||||
getOutliningSpans: fileName =>
|
||||
realLanguageService.getOutliningSpans(fileName),
|
||||
getTodoComments: getEmptyResult,
|
||||
getIndentationAtPosition: (fileName, position, options) =>
|
||||
realLanguageService.getIndentationAtPosition(fileName, position, options),
|
||||
getFormattingEditsForRange: (fileName, start, end, options) =>
|
||||
realLanguageService.getFormattingEditsForRange(fileName, start, end, options),
|
||||
getFormattingEditsForDocument: (fileName, options) =>
|
||||
realLanguageService.getFormattingEditsForDocument(fileName, options),
|
||||
getFormattingEditsAfterKeystroke: (fileName, position, key, options) =>
|
||||
realLanguageService.getFormattingEditsAfterKeystroke(fileName, position, key, options),
|
||||
getDocCommentTemplateAtPosition: (fileName, position) =>
|
||||
realLanguageService.getDocCommentTemplateAtPosition(fileName, position),
|
||||
isValidBraceCompletionAtPosition: (fileName, position, openingBrace) =>
|
||||
realLanguageService.isValidBraceCompletionAtPosition(fileName, position, openingBrace),
|
||||
getEmitOutput: getUndefined,
|
||||
getProgram: () =>
|
||||
realLanguageService.getProgram(),
|
||||
getNonBoundSourceFile: fileName =>
|
||||
realLanguageService.getNonBoundSourceFile(fileName),
|
||||
dispose: () =>
|
||||
realLanguageService.dispose(),
|
||||
getCompletionEntrySymbol: getUndefined,
|
||||
getImplementationAtPosition: getEmptyResult,
|
||||
getSourceFile: fileName =>
|
||||
realLanguageService.getSourceFile(fileName),
|
||||
getCodeFixesAtPosition: getEmptyResult
|
||||
};
|
||||
}
|
||||
|
||||
export abstract class Project {
|
||||
private rootFiles: ScriptInfo[] = [];
|
||||
private rootFilesMap: FileMap<ScriptInfo> = createFileMap<ScriptInfo>();
|
||||
private lsHost: ServerLanguageServiceHost;
|
||||
private lsHost: LSHost;
|
||||
private program: ts.Program;
|
||||
|
||||
private cachedUnresolvedImportsPerFile = new UnresolvedImportsMap();
|
||||
private lastCachedUnresolvedImportsList: SortedReadonlyArray<string>;
|
||||
|
||||
private languageService: LanguageService;
|
||||
private readonly languageService: LanguageService;
|
||||
// wrapper over the real language service that will suppress all semantic operations
|
||||
private readonly noSemanticFeaturesLanguageService: LanguageService;
|
||||
|
||||
public languageServiceEnabled = true;
|
||||
|
||||
builder: Builder;
|
||||
/**
|
||||
* Set of files that was returned from the last call to getChangesSinceVersion.
|
||||
@@ -147,7 +233,7 @@ namespace ts.server {
|
||||
readonly projectService: ProjectService,
|
||||
private documentRegistry: ts.DocumentRegistry,
|
||||
hasExplicitListOfFiles: boolean,
|
||||
public languageServiceEnabled: boolean,
|
||||
languageServiceEnabled: boolean,
|
||||
private compilerOptions: CompilerOptions,
|
||||
public compileOnSaveEnabled: boolean) {
|
||||
|
||||
@@ -161,14 +247,17 @@ namespace ts.server {
|
||||
this.compilerOptions.allowNonTsExtensions = true;
|
||||
}
|
||||
|
||||
if (this.projectKind === ProjectKind.Inferred) {
|
||||
this.compilerOptions.noEmitOverwritenFiles = true;
|
||||
if (this.projectKind === ProjectKind.Inferred || this.projectKind === ProjectKind.External) {
|
||||
this.compilerOptions.noEmitForJsFiles = true;
|
||||
}
|
||||
|
||||
if (languageServiceEnabled) {
|
||||
this.enableLanguageService();
|
||||
}
|
||||
else {
|
||||
this.lsHost = new LSHost(this.projectService.host, this, this.projectService.cancellationToken);
|
||||
this.lsHost.setCompilationSettings(this.compilerOptions);
|
||||
|
||||
this.languageService = ts.createLanguageService(this.lsHost, this.documentRegistry);
|
||||
this.noSemanticFeaturesLanguageService = createNoSemanticFeaturesWrapper(this.languageService);
|
||||
|
||||
if (!languageServiceEnabled) {
|
||||
this.disableLanguageService();
|
||||
}
|
||||
|
||||
@@ -184,7 +273,9 @@ namespace ts.server {
|
||||
if (ensureSynchronized) {
|
||||
this.updateGraph();
|
||||
}
|
||||
return this.languageService;
|
||||
return this.languageServiceEnabled
|
||||
? this.languageService
|
||||
: this.noSemanticFeaturesLanguageService;
|
||||
}
|
||||
|
||||
getCompileOnSaveAffectedFileList(scriptInfo: ScriptInfo): string[] {
|
||||
@@ -200,18 +291,20 @@ namespace ts.server {
|
||||
}
|
||||
|
||||
enableLanguageService() {
|
||||
const lsHost = new LSHost(this.projectService.host, this, this.projectService.cancellationToken);
|
||||
lsHost.setCompilationSettings(this.compilerOptions);
|
||||
this.languageService = ts.createLanguageService(lsHost, this.documentRegistry);
|
||||
|
||||
this.lsHost = lsHost;
|
||||
if (this.languageServiceEnabled) {
|
||||
return;
|
||||
}
|
||||
this.languageServiceEnabled = true;
|
||||
this.projectService.onUpdateLanguageServiceStateForProject(this, /*languageServiceEnabled*/ true);
|
||||
}
|
||||
|
||||
disableLanguageService() {
|
||||
this.languageService = nullLanguageService;
|
||||
this.lsHost = nullLanguageServiceHost;
|
||||
if (!this.languageServiceEnabled) {
|
||||
return;
|
||||
}
|
||||
this.languageService.cleanupSemanticCache();
|
||||
this.languageServiceEnabled = false;
|
||||
this.projectService.onUpdateLanguageServiceStateForProject(this, /*languageServiceEnabled*/ false);
|
||||
}
|
||||
|
||||
abstract getProjectName(): string;
|
||||
@@ -676,12 +769,12 @@ namespace ts.server {
|
||||
// Used to keep track of what directories are watched for this project
|
||||
directoriesWatchedForTsconfig: string[] = [];
|
||||
|
||||
constructor(projectService: ProjectService, documentRegistry: ts.DocumentRegistry, languageServiceEnabled: boolean, compilerOptions: CompilerOptions) {
|
||||
constructor(projectService: ProjectService, documentRegistry: ts.DocumentRegistry, compilerOptions: CompilerOptions) {
|
||||
super(ProjectKind.Inferred,
|
||||
projectService,
|
||||
documentRegistry,
|
||||
/*files*/ undefined,
|
||||
languageServiceEnabled,
|
||||
/*languageServiceEnabled*/ true,
|
||||
compilerOptions,
|
||||
/*compileOnSaveEnabled*/ false);
|
||||
|
||||
|
||||
@@ -1814,6 +1814,27 @@ namespace ts.server.protocol {
|
||||
event: "configFileDiag";
|
||||
}
|
||||
|
||||
export type ProjectLanguageServiceStateEventName = "projectLanguageServiceState";
|
||||
export interface ProjectLanguageServiceStateEvent extends Event {
|
||||
event: ProjectLanguageServiceStateEventName;
|
||||
body?: ProjectLanguageServiceStateEventBody;
|
||||
}
|
||||
|
||||
export interface ProjectLanguageServiceStateEventBody {
|
||||
/**
|
||||
* Project name that has changes in the state of language service.
|
||||
* For configured projects this will be the config file path.
|
||||
* For external projects this will be the name of the projects specified when project was open.
|
||||
* For inferred projects this event is not raised.
|
||||
*/
|
||||
projectName: string;
|
||||
/**
|
||||
* True if language service state switched from disabled to enabled
|
||||
* and false otherwise.
|
||||
*/
|
||||
languageServiceEnabled: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Arguments for reload request.
|
||||
*/
|
||||
@@ -2081,6 +2102,15 @@ namespace ts.server.protocol {
|
||||
* Comma separated list of installed typing packages
|
||||
*/
|
||||
installedPackages: string;
|
||||
/**
|
||||
* true if install request succeeded, otherwise - false
|
||||
*/
|
||||
installSuccess: boolean;
|
||||
|
||||
/**
|
||||
* version of typings installer
|
||||
*/
|
||||
typingsInstallerVersion: string;
|
||||
}
|
||||
|
||||
export interface NavBarResponse extends Response {
|
||||
|
||||
@@ -299,7 +299,9 @@ namespace ts.server {
|
||||
const body: protocol.TypingsInstalledTelemetryEventBody = {
|
||||
telemetryEventName: "typingsInstalled",
|
||||
payload: {
|
||||
installedPackages: response.packagesToInstall.join(",")
|
||||
installedPackages: response.packagesToInstall.join(","),
|
||||
installSuccess: response.installSuccess,
|
||||
typingsInstallerVersion: response.typingsInstallerVersion
|
||||
}
|
||||
};
|
||||
const eventName: protocol.TelemetryEventName = "telemetry";
|
||||
|
||||
+10
-2
@@ -199,15 +199,23 @@ namespace ts.server {
|
||||
|
||||
private defaultEventHandler(event: ProjectServiceEvent) {
|
||||
switch (event.eventName) {
|
||||
case "context":
|
||||
case ContextEvent:
|
||||
const { project, fileName } = event.data;
|
||||
this.projectService.logger.info(`got context event, updating diagnostics for ${fileName}`);
|
||||
this.updateErrorCheck([{ fileName, project }], this.changeSeq,
|
||||
(n) => n === this.changeSeq, 100);
|
||||
break;
|
||||
case "configFileDiag":
|
||||
case ConfigFileDiagEvent:
|
||||
const { triggerFile, configFileName, diagnostics } = event.data;
|
||||
this.configFileDiagnosticEvent(triggerFile, configFileName, diagnostics);
|
||||
break;
|
||||
case ProjectLanguageServiceStateEvent:
|
||||
const eventName: protocol.ProjectLanguageServiceStateEventName = "projectLanguageServiceState";
|
||||
this.event(<protocol.ProjectLanguageServiceStateEventBody>{
|
||||
projectName: event.data.project.getProjectName(),
|
||||
languageServiceEnabled: event.data.languageServiceEnabled
|
||||
}, eventName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+2
@@ -68,6 +68,8 @@ declare namespace ts.server {
|
||||
export interface TypingsInstallEvent extends TypingInstallerResponse {
|
||||
readonly packagesToInstall: ReadonlyArray<string>;
|
||||
readonly kind: EventInstall;
|
||||
readonly installSuccess: boolean;
|
||||
readonly typingsInstallerVersion: string;
|
||||
}
|
||||
|
||||
export interface InstallTypingHost extends JsTyping.TypingResolutionHost {
|
||||
|
||||
@@ -61,17 +61,12 @@ namespace ts.server.typingsInstaller {
|
||||
return combinePaths(normalizeSlashes(globalTypingsCacheLocation), `node_modules/${TypesRegistryPackageName}/index.json`);
|
||||
}
|
||||
|
||||
|
||||
type Exec = {
|
||||
(command: string, options: { cwd: string }, callback?: (error: Error, stdout: string, stderr: string) => void): any
|
||||
};
|
||||
|
||||
type ExecSync = {
|
||||
(command: string, options: { cwd: string, stdio: "ignore" }): any
|
||||
};
|
||||
(command: string, options: { cwd: string, stdio?: "ignore" }): any
|
||||
}
|
||||
|
||||
export class NodeTypingsInstaller extends TypingsInstaller {
|
||||
private readonly exec: Exec;
|
||||
private readonly execSync: ExecSync;
|
||||
private readonly npmPath: string;
|
||||
readonly typesRegistry: Map<void>;
|
||||
|
||||
@@ -87,8 +82,7 @@ namespace ts.server.typingsInstaller {
|
||||
this.log.writeLine(`Process id: ${process.pid}`);
|
||||
}
|
||||
this.npmPath = getNPMLocation(process.argv[0]);
|
||||
let execSync: ExecSync;
|
||||
({ exec: this.exec, execSync } = require("child_process"));
|
||||
({ execSync: this.execSync } = require("child_process"));
|
||||
|
||||
this.ensurePackageDirectoryExists(globalTypingsCacheLocation);
|
||||
|
||||
@@ -96,7 +90,7 @@ namespace ts.server.typingsInstaller {
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`Updating ${TypesRegistryPackageName} npm package...`);
|
||||
}
|
||||
execSync(`${this.npmPath} install ${TypesRegistryPackageName}`, { cwd: globalTypingsCacheLocation, stdio: "ignore" });
|
||||
this.execSync(`${this.npmPath} install ${TypesRegistryPackageName}`, { cwd: globalTypingsCacheLocation, stdio: "ignore" });
|
||||
}
|
||||
catch (e) {
|
||||
if (this.log.isEnabled()) {
|
||||
@@ -135,13 +129,21 @@ namespace ts.server.typingsInstaller {
|
||||
}
|
||||
const command = `${this.npmPath} install ${args.join(" ")} --save-dev`;
|
||||
const start = Date.now();
|
||||
this.exec(command, { cwd }, (_err, stdout, stderr) => {
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`npm install #${requestId} took: ${Date.now() - start} ms${sys.newLine}stdout: ${stdout}${sys.newLine}stderr: ${stderr}`);
|
||||
}
|
||||
// treat any output on stdout as success
|
||||
onRequestCompleted(!!stdout);
|
||||
});
|
||||
let stdout: Buffer;
|
||||
let stderr: Buffer;
|
||||
let hasError = false;
|
||||
try {
|
||||
stdout = this.execSync(command, { cwd });
|
||||
}
|
||||
catch (e) {
|
||||
stdout = e.stdout;
|
||||
stderr = e.stderr;
|
||||
hasError = true;
|
||||
}
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`npm install #${requestId} took: ${Date.now() - start} ms${sys.newLine}stdout: ${stdout && stdout.toString()}${sys.newLine}stderr: ${stderr && stderr.toString()}`);
|
||||
}
|
||||
onRequestCompleted(!hasError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,17 @@ namespace ts.server.typingsInstaller {
|
||||
writeLine: noop
|
||||
};
|
||||
|
||||
function typingToFileName(cachePath: string, packageName: string, installTypingHost: InstallTypingHost): string {
|
||||
const result = resolveModuleName(packageName, combinePaths(cachePath, "index.d.ts"), { moduleResolution: ModuleResolutionKind.NodeJs }, installTypingHost);
|
||||
return result.resolvedModule && result.resolvedModule.resolvedFileName;
|
||||
function typingToFileName(cachePath: string, packageName: string, installTypingHost: InstallTypingHost, log: Log): string {
|
||||
try {
|
||||
const result = resolveModuleName(packageName, combinePaths(cachePath, "index.d.ts"), { moduleResolution: ModuleResolutionKind.NodeJs }, installTypingHost);
|
||||
return result.resolvedModule && result.resolvedModule.resolvedFileName;
|
||||
}
|
||||
catch (e) {
|
||||
if (log.isEnabled()) {
|
||||
log.writeLine(`Failed to resolve ${packageName} in folder '${cachePath}': ${(<Error>e).message}`);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export enum PackageNameValidationResult {
|
||||
@@ -69,7 +77,7 @@ namespace ts.server.typingsInstaller {
|
||||
requestId: number;
|
||||
args: string[];
|
||||
cwd: string;
|
||||
onRequestCompleted: RequestCompletedAction
|
||||
onRequestCompleted: RequestCompletedAction;
|
||||
};
|
||||
|
||||
export abstract class TypingsInstaller {
|
||||
@@ -192,8 +200,9 @@ namespace ts.server.typingsInstaller {
|
||||
if (!packageName) {
|
||||
continue;
|
||||
}
|
||||
const typingFile = typingToFileName(cacheLocation, packageName, this.installTypingHost);
|
||||
const typingFile = typingToFileName(cacheLocation, packageName, this.installTypingHost, this.log);
|
||||
if (!typingFile) {
|
||||
this.missingTypingsSet[packageName] = true;
|
||||
continue;
|
||||
}
|
||||
const existingTypingFile = this.packageNameToTypingLocation[packageName];
|
||||
@@ -218,19 +227,19 @@ namespace ts.server.typingsInstaller {
|
||||
this.knownCachesSet[cacheLocation] = true;
|
||||
}
|
||||
|
||||
private filterAndMapToScopedName(typingsToInstall: string[]) {
|
||||
private filterTypings(typingsToInstall: string[]) {
|
||||
if (typingsToInstall.length === 0) {
|
||||
return typingsToInstall;
|
||||
}
|
||||
const result: string[] = [];
|
||||
for (const typing of typingsToInstall) {
|
||||
if (this.missingTypingsSet[typing]) {
|
||||
if (this.missingTypingsSet[typing] || this.packageNameToTypingLocation[typing]) {
|
||||
continue;
|
||||
}
|
||||
const validationResult = validatePackageName(typing);
|
||||
if (validationResult === PackageNameValidationResult.Ok) {
|
||||
if (typing in this.typesRegistry) {
|
||||
result.push(`@types/${typing}`);
|
||||
result.push(typing);
|
||||
}
|
||||
else {
|
||||
if (this.log.isEnabled()) {
|
||||
@@ -286,7 +295,8 @@ namespace ts.server.typingsInstaller {
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`Installing typings ${JSON.stringify(typingsToInstall)}`);
|
||||
}
|
||||
const scopedTypings = this.filterAndMapToScopedName(typingsToInstall);
|
||||
const filteredTypings = this.filterTypings(typingsToInstall);
|
||||
const scopedTypings = filteredTypings.map(x => `@types/${x}`);
|
||||
if (scopedTypings.length === 0) {
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`All typings are known to be missing or invalid - no need to go any further`);
|
||||
@@ -303,26 +313,31 @@ namespace ts.server.typingsInstaller {
|
||||
if (this.telemetryEnabled) {
|
||||
this.sendResponse(<TypingsInstallEvent>{
|
||||
kind: EventInstall,
|
||||
packagesToInstall: scopedTypings
|
||||
packagesToInstall: scopedTypings,
|
||||
installSuccess: ok,
|
||||
typingsInstallerVersion: ts.version // qualified explicitly to prevent occasional shadowing
|
||||
});
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`install request failed, marking packages as missing to prevent repeated requests: ${JSON.stringify(filteredTypings)}`);
|
||||
}
|
||||
for (const typing of filteredTypings) {
|
||||
this.missingTypingsSet[typing] = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: watch project directory
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`Requested to install typings ${JSON.stringify(scopedTypings)}, installed typings ${JSON.stringify(scopedTypings)}`);
|
||||
this.log.writeLine(`Installed typings ${JSON.stringify(scopedTypings)}`);
|
||||
}
|
||||
const installedTypingFiles: string[] = [];
|
||||
for (const t of scopedTypings) {
|
||||
const packageName = getBaseFileName(t);
|
||||
if (!packageName) {
|
||||
continue;
|
||||
}
|
||||
const typingFile = typingToFileName(cachePath, packageName, this.installTypingHost);
|
||||
for (const packageName of filteredTypings) {
|
||||
const typingFile = typingToFileName(cachePath, packageName, this.installTypingHost, this.log);
|
||||
if (!typingFile) {
|
||||
this.missingTypingsSet[packageName] = true;
|
||||
continue;
|
||||
}
|
||||
if (!this.packageNameToTypingLocation[packageName]) {
|
||||
@@ -380,7 +395,7 @@ namespace ts.server.typingsInstaller {
|
||||
compilerOptions: request.compilerOptions,
|
||||
typings,
|
||||
unresolvedImports: request.unresolvedImports,
|
||||
kind: server.ActionSet
|
||||
kind: ActionSet
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ namespace ts.server {
|
||||
|
||||
export const emptyArray: ReadonlyArray<any> = [];
|
||||
|
||||
|
||||
export interface Logger {
|
||||
close(): void;
|
||||
hasLevel(level: LogLevel): boolean;
|
||||
@@ -160,68 +159,6 @@ namespace ts.server {
|
||||
}
|
||||
};
|
||||
}
|
||||
function throwLanguageServiceIsDisabledError(): never {
|
||||
throw new Error("LanguageService is disabled");
|
||||
}
|
||||
|
||||
export const nullLanguageService: LanguageService = {
|
||||
cleanupSemanticCache: throwLanguageServiceIsDisabledError,
|
||||
getSyntacticDiagnostics: throwLanguageServiceIsDisabledError,
|
||||
getSemanticDiagnostics: throwLanguageServiceIsDisabledError,
|
||||
getCompilerOptionsDiagnostics: throwLanguageServiceIsDisabledError,
|
||||
getSyntacticClassifications: throwLanguageServiceIsDisabledError,
|
||||
getEncodedSyntacticClassifications: throwLanguageServiceIsDisabledError,
|
||||
getSemanticClassifications: throwLanguageServiceIsDisabledError,
|
||||
getEncodedSemanticClassifications: throwLanguageServiceIsDisabledError,
|
||||
getCompletionsAtPosition: throwLanguageServiceIsDisabledError,
|
||||
findReferences: throwLanguageServiceIsDisabledError,
|
||||
getCompletionEntryDetails: throwLanguageServiceIsDisabledError,
|
||||
getQuickInfoAtPosition: throwLanguageServiceIsDisabledError,
|
||||
findRenameLocations: throwLanguageServiceIsDisabledError,
|
||||
getNameOrDottedNameSpan: throwLanguageServiceIsDisabledError,
|
||||
getBreakpointStatementAtPosition: throwLanguageServiceIsDisabledError,
|
||||
getBraceMatchingAtPosition: throwLanguageServiceIsDisabledError,
|
||||
getSignatureHelpItems: throwLanguageServiceIsDisabledError,
|
||||
getDefinitionAtPosition: throwLanguageServiceIsDisabledError,
|
||||
getRenameInfo: throwLanguageServiceIsDisabledError,
|
||||
getTypeDefinitionAtPosition: throwLanguageServiceIsDisabledError,
|
||||
getReferencesAtPosition: throwLanguageServiceIsDisabledError,
|
||||
getDocumentHighlights: throwLanguageServiceIsDisabledError,
|
||||
getOccurrencesAtPosition: throwLanguageServiceIsDisabledError,
|
||||
getNavigateToItems: throwLanguageServiceIsDisabledError,
|
||||
getNavigationBarItems: throwLanguageServiceIsDisabledError,
|
||||
getNavigationTree: throwLanguageServiceIsDisabledError,
|
||||
getOutliningSpans: throwLanguageServiceIsDisabledError,
|
||||
getTodoComments: throwLanguageServiceIsDisabledError,
|
||||
getIndentationAtPosition: throwLanguageServiceIsDisabledError,
|
||||
getFormattingEditsForRange: throwLanguageServiceIsDisabledError,
|
||||
getFormattingEditsForDocument: throwLanguageServiceIsDisabledError,
|
||||
getFormattingEditsAfterKeystroke: throwLanguageServiceIsDisabledError,
|
||||
getDocCommentTemplateAtPosition: throwLanguageServiceIsDisabledError,
|
||||
isValidBraceCompletionAtPosition: throwLanguageServiceIsDisabledError,
|
||||
getEmitOutput: throwLanguageServiceIsDisabledError,
|
||||
getProgram: throwLanguageServiceIsDisabledError,
|
||||
getNonBoundSourceFile: throwLanguageServiceIsDisabledError,
|
||||
dispose: throwLanguageServiceIsDisabledError,
|
||||
getCompletionEntrySymbol: throwLanguageServiceIsDisabledError,
|
||||
getImplementationAtPosition: throwLanguageServiceIsDisabledError,
|
||||
getSourceFile: throwLanguageServiceIsDisabledError,
|
||||
getCodeFixesAtPosition: throwLanguageServiceIsDisabledError
|
||||
};
|
||||
|
||||
export interface ServerLanguageServiceHost {
|
||||
setCompilationSettings(options: CompilerOptions): void;
|
||||
notifyFileRemoved(info: ScriptInfo): void;
|
||||
startRecordingFilesWithChangedResolutions(): void;
|
||||
finishRecordingFilesWithChangedResolutions(): Path[];
|
||||
}
|
||||
|
||||
export const nullLanguageServiceHost: ServerLanguageServiceHost = {
|
||||
setCompilationSettings: () => undefined,
|
||||
notifyFileRemoved: () => undefined,
|
||||
startRecordingFilesWithChangedResolutions: () => undefined,
|
||||
finishRecordingFilesWithChangedResolutions: () => undefined
|
||||
};
|
||||
|
||||
export interface ProjectOptions {
|
||||
/**
|
||||
|
||||
@@ -264,7 +264,7 @@ namespace ts.BreakpointResolver {
|
||||
// a or ...c or d: x from
|
||||
// [a, b, ...c] or { a, b } or { d: x } from destructuring pattern
|
||||
if ((node.kind === SyntaxKind.Identifier ||
|
||||
node.kind == SyntaxKind.SpreadElementExpression ||
|
||||
node.kind == SyntaxKind.SpreadElement ||
|
||||
node.kind === SyntaxKind.PropertyAssignment ||
|
||||
node.kind === SyntaxKind.ShorthandPropertyAssignment) &&
|
||||
isArrayLiteralOrObjectLiteralDestructuringPattern(node.parent)) {
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
///<reference path='superFixes.ts' />
|
||||
///<reference path='unusedIdentifierFixes.ts' />
|
||||
@@ -0,0 +1,167 @@
|
||||
/* @internal */
|
||||
namespace ts.codefix {
|
||||
registerCodeFix({
|
||||
errorCodes: [
|
||||
Diagnostics._0_is_declared_but_never_used.code,
|
||||
Diagnostics.Property_0_is_declared_but_never_used.code
|
||||
],
|
||||
getCodeActions: (context: CodeFixContext) => {
|
||||
const sourceFile = context.sourceFile;
|
||||
const start = context.span.start;
|
||||
|
||||
let token = getTokenAtPosition(sourceFile, start);
|
||||
|
||||
// this handles var ["computed"] = 12;
|
||||
if (token.kind === SyntaxKind.OpenBracketToken) {
|
||||
token = getTokenAtPosition(sourceFile, start + 1);
|
||||
}
|
||||
|
||||
switch (token.kind) {
|
||||
case ts.SyntaxKind.Identifier:
|
||||
switch (token.parent.kind) {
|
||||
case ts.SyntaxKind.VariableDeclaration:
|
||||
switch (token.parent.parent.parent.kind) {
|
||||
case SyntaxKind.ForStatement:
|
||||
const forStatement = <ForStatement>token.parent.parent.parent;
|
||||
const forInitializer = <VariableDeclarationList>forStatement.initializer;
|
||||
if (forInitializer.declarations.length === 1) {
|
||||
return createCodeFix("", forInitializer.pos, forInitializer.end - forInitializer.pos);
|
||||
}
|
||||
else {
|
||||
return removeSingleItem(forInitializer.declarations, token);
|
||||
}
|
||||
|
||||
case SyntaxKind.ForOfStatement:
|
||||
const forOfStatement = <ForOfStatement>token.parent.parent.parent;
|
||||
if (forOfStatement.initializer.kind === SyntaxKind.VariableDeclarationList) {
|
||||
const forOfInitializer = <VariableDeclarationList>forOfStatement.initializer;
|
||||
return createCodeFix("{}", forOfInitializer.declarations[0].pos, forOfInitializer.declarations[0].end - forOfInitializer.declarations[0].pos);
|
||||
}
|
||||
break;
|
||||
|
||||
case SyntaxKind.ForInStatement:
|
||||
// There is no valid fix in the case of:
|
||||
// for .. in
|
||||
return undefined;
|
||||
|
||||
case SyntaxKind.CatchClause:
|
||||
const catchClause = <CatchClause>token.parent.parent;
|
||||
const parameter = catchClause.variableDeclaration.getChildren()[0];
|
||||
return createCodeFix("", parameter.pos, parameter.end - parameter.pos);
|
||||
|
||||
default:
|
||||
const variableStatement = <VariableStatement>token.parent.parent.parent;
|
||||
if (variableStatement.declarationList.declarations.length === 1) {
|
||||
return createCodeFix("", variableStatement.pos, variableStatement.end - variableStatement.pos);
|
||||
}
|
||||
else {
|
||||
const declarations = variableStatement.declarationList.declarations;
|
||||
return removeSingleItem(declarations, token);
|
||||
}
|
||||
}
|
||||
|
||||
case SyntaxKind.TypeParameter:
|
||||
const typeParameters = (<DeclarationWithTypeParameters>token.parent.parent).typeParameters;
|
||||
if (typeParameters.length === 1) {
|
||||
return createCodeFix("", token.parent.pos - 1, token.parent.end - token.parent.pos + 2);
|
||||
}
|
||||
else {
|
||||
return removeSingleItem(typeParameters, token);
|
||||
}
|
||||
|
||||
case ts.SyntaxKind.Parameter:
|
||||
const functionDeclaration = <FunctionDeclaration>token.parent.parent;
|
||||
if (functionDeclaration.parameters.length === 1) {
|
||||
return createCodeFix("", token.parent.pos, token.parent.end - token.parent.pos);
|
||||
}
|
||||
else {
|
||||
return removeSingleItem(functionDeclaration.parameters, token);
|
||||
}
|
||||
|
||||
// handle case where 'import a = A;'
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
const importEquals = findImportDeclaration(token);
|
||||
return createCodeFix("", importEquals.pos, importEquals.end - importEquals.pos);
|
||||
|
||||
case SyntaxKind.ImportSpecifier:
|
||||
const namedImports = <NamedImports>token.parent.parent;
|
||||
if (namedImports.elements.length === 1) {
|
||||
// Only 1 import and it is unused. So the entire declaration should be removed.
|
||||
const importSpec = findImportDeclaration(token);
|
||||
return createCodeFix("", importSpec.pos, importSpec.end - importSpec.pos);
|
||||
}
|
||||
else {
|
||||
return removeSingleItem(namedImports.elements, token);
|
||||
}
|
||||
|
||||
// handle case where "import d, * as ns from './file'"
|
||||
// or "'import {a, b as ns} from './file'"
|
||||
case SyntaxKind.ImportClause: // this covers both 'import |d|' and 'import |d,| *'
|
||||
const importClause = <ImportClause>token.parent;
|
||||
if (!importClause.namedBindings) { // |import d from './file'| or |import * as ns from './file'|
|
||||
const importDecl = findImportDeclaration(importClause);
|
||||
return createCodeFix("", importDecl.pos, importDecl.end - importDecl.pos);
|
||||
}
|
||||
else { // import |d,| * as ns from './file'
|
||||
return createCodeFix("", importClause.name.pos, importClause.namedBindings.pos - importClause.name.pos);
|
||||
}
|
||||
|
||||
case SyntaxKind.NamespaceImport:
|
||||
const namespaceImport = <NamespaceImport>token.parent;
|
||||
if (namespaceImport.name == token && !(<ImportClause>namespaceImport.parent).name) {
|
||||
const importDecl = findImportDeclaration(namespaceImport);
|
||||
return createCodeFix("", importDecl.pos, importDecl.end - importDecl.pos);
|
||||
}
|
||||
else {
|
||||
const start = (<ImportClause>namespaceImport.parent).name.end;
|
||||
return createCodeFix("", start, (<ImportClause>namespaceImport.parent).namedBindings.end - start);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
return createCodeFix("", token.parent.pos, token.parent.end - token.parent.pos);
|
||||
|
||||
case SyntaxKind.NamespaceImport:
|
||||
return createCodeFix("", token.parent.pos, token.parent.end - token.parent.pos);
|
||||
}
|
||||
if (isDeclarationName(token)) {
|
||||
return createCodeFix("", token.parent.pos, token.parent.end - token.parent.pos);
|
||||
}
|
||||
else if (isLiteralComputedPropertyDeclarationName(token)) {
|
||||
return createCodeFix("", token.parent.parent.pos, token.parent.parent.end - token.parent.parent.pos);
|
||||
}
|
||||
else {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function findImportDeclaration(token: Node): Node {
|
||||
let importDecl = token;
|
||||
while (importDecl.kind != SyntaxKind.ImportDeclaration && importDecl.parent) {
|
||||
importDecl = importDecl.parent;
|
||||
}
|
||||
|
||||
return importDecl;
|
||||
}
|
||||
|
||||
function createCodeFix(newText: string, start: number, length: number): CodeAction[] {
|
||||
return [{
|
||||
description: getLocaleSpecificMessage(Diagnostics.Remove_unused_identifiers),
|
||||
changes: [{
|
||||
fileName: sourceFile.fileName,
|
||||
textChanges: [{ newText, span: { start, length } }]
|
||||
}]
|
||||
}];
|
||||
}
|
||||
|
||||
function removeSingleItem<T extends Node>(elements: NodeArray<T>, token: T): CodeAction[] {
|
||||
if (elements[0] === token.parent) {
|
||||
return createCodeFix("", token.parent.pos, token.parent.end - token.parent.pos + 1);
|
||||
}
|
||||
else {
|
||||
return createCodeFix("", token.parent.pos - 1, token.parent.end - token.parent.pos + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1188,7 +1188,7 @@ namespace ts.FindAllReferences {
|
||||
if (node.name.kind === SyntaxKind.ComputedPropertyName) {
|
||||
const nameExpression = (<ComputedPropertyName>node.name).expression;
|
||||
// treat computed property names where expression is string/numeric literal as just string/numeric literal
|
||||
if (isStringOrNumericLiteral(nameExpression.kind)) {
|
||||
if (isStringOrNumericLiteral(nameExpression)) {
|
||||
return (<LiteralExpression>nameExpression).text;
|
||||
}
|
||||
return undefined;
|
||||
|
||||
@@ -1205,7 +1205,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function cleanupSemanticCache(): void {
|
||||
// TODO: Should we jettison the program (or it's type checker) here?
|
||||
program = undefined;
|
||||
}
|
||||
|
||||
function dispose(): void {
|
||||
|
||||
@@ -1060,8 +1060,15 @@ namespace ts {
|
||||
return this.forwardJSONCall(`resolveModuleName('${fileName}')`, () => {
|
||||
const compilerOptions = <CompilerOptions>JSON.parse(compilerOptionsJson);
|
||||
const result = resolveModuleName(moduleName, normalizeSlashes(fileName), compilerOptions, this.host);
|
||||
const resolvedFileName = result.resolvedModule ? result.resolvedModule.resolvedFileName : undefined;
|
||||
if (resolvedFileName && !compilerOptions.allowJs && fileExtensionIs(resolvedFileName, ".js")) {
|
||||
return {
|
||||
resolvedFileName: undefined,
|
||||
failedLookupLocations: []
|
||||
};
|
||||
}
|
||||
return {
|
||||
resolvedFileName: result.resolvedModule ? result.resolvedModule.resolvedFileName : undefined,
|
||||
resolvedFileName,
|
||||
failedLookupLocations: result.failedLookupLocations
|
||||
};
|
||||
});
|
||||
@@ -1261,11 +1268,8 @@ namespace TypeScript.Services {
|
||||
export const TypeScriptServicesFactory = ts.TypeScriptServicesFactory;
|
||||
}
|
||||
|
||||
/* tslint:disable:no-unused-variable */
|
||||
// 'toolsVersion' gets consumed by the managed side, so it's not unused.
|
||||
// TODO: it should be moved into a namespace though.
|
||||
|
||||
/* @internal */
|
||||
const toolsVersion = "2.1";
|
||||
|
||||
/* tslint:enable:no-unused-variable */
|
||||
const toolsVersion = "2.2";
|
||||
@@ -272,11 +272,9 @@ namespace ts.SymbolDisplay {
|
||||
displayParts.push(punctuationPart(SyntaxKind.CloseParenToken));
|
||||
displayParts.push(spacePart());
|
||||
addFullSymbolName(symbol);
|
||||
displayParts.push(spacePart());
|
||||
displayParts.push(keywordPart(SyntaxKind.InKeyword));
|
||||
displayParts.push(spacePart());
|
||||
if (symbol.parent) {
|
||||
// Class/Interface type parameter
|
||||
addInPrefix();
|
||||
addFullSymbolName(symbol.parent, enclosingDeclaration);
|
||||
writeTypeParametersOfSymbol(symbol.parent, enclosingDeclaration);
|
||||
}
|
||||
@@ -288,6 +286,7 @@ namespace ts.SymbolDisplay {
|
||||
|
||||
if (declaration) {
|
||||
if (isFunctionLikeKind(declaration.kind)) {
|
||||
addInPrefix();
|
||||
const signature = typeChecker.getSignatureFromDeclaration(<SignatureDeclaration>declaration);
|
||||
if (declaration.kind === SyntaxKind.ConstructSignature) {
|
||||
displayParts.push(keywordPart(SyntaxKind.NewKeyword));
|
||||
@@ -298,10 +297,11 @@ namespace ts.SymbolDisplay {
|
||||
}
|
||||
addRange(displayParts, signatureToDisplayParts(typeChecker, signature, sourceFile, TypeFormatFlags.WriteTypeArgumentsOfSignature));
|
||||
}
|
||||
else {
|
||||
else if (declaration.kind === SyntaxKind.TypeAliasDeclaration) {
|
||||
// Type alias type parameter
|
||||
// For example
|
||||
// type list<T> = T[]; // Both T will go through same code path
|
||||
addInPrefix();
|
||||
displayParts.push(keywordPart(SyntaxKind.TypeKeyword));
|
||||
displayParts.push(spacePart());
|
||||
addFullSymbolName(declaration.symbol);
|
||||
@@ -439,6 +439,12 @@ namespace ts.SymbolDisplay {
|
||||
}
|
||||
}
|
||||
|
||||
function addInPrefix() {
|
||||
displayParts.push(spacePart());
|
||||
displayParts.push(keywordPart(SyntaxKind.InKeyword));
|
||||
displayParts.push(spacePart());
|
||||
}
|
||||
|
||||
function addFullSymbolName(symbol: Symbol, enclosingDeclaration?: Node) {
|
||||
const fullSymbolDisplayParts = symbolToDisplayParts(typeChecker, symbol, enclosingDeclaration || sourceFile, /*meaning*/ undefined,
|
||||
SymbolFormatFlags.WriteTypeParametersOrArguments | SymbolFormatFlags.UseOnlyExternalAliasing);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{
|
||||
{
|
||||
"compilerOptions": {
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
@@ -12,7 +12,8 @@
|
||||
"declaration": true,
|
||||
"target": "es5",
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true
|
||||
"noUnusedParameters": true,
|
||||
"types": []
|
||||
},
|
||||
"files": [
|
||||
"../compiler/core.ts",
|
||||
@@ -28,6 +29,7 @@
|
||||
"../compiler/visitor.ts",
|
||||
"../compiler/transformers/ts.ts",
|
||||
"../compiler/transformers/jsx.ts",
|
||||
"../compiler/transformers/esnext.ts",
|
||||
"../compiler/transformers/es2017.ts",
|
||||
"../compiler/transformers/es2016.ts",
|
||||
"../compiler/transformers/es2015.ts",
|
||||
|
||||
@@ -530,8 +530,8 @@ namespace ts {
|
||||
case SyntaxKind.DeleteExpression:
|
||||
case SyntaxKind.VoidExpression:
|
||||
case SyntaxKind.YieldExpression:
|
||||
case SyntaxKind.SpreadElementExpression:
|
||||
const unaryWordExpression = (<TypeOfExpression | DeleteExpression | VoidExpression | YieldExpression | SpreadElementExpression>n);
|
||||
case SyntaxKind.SpreadElement:
|
||||
const unaryWordExpression = n as (TypeOfExpression | DeleteExpression | VoidExpression | YieldExpression | SpreadElement);
|
||||
return isCompletedNode(unaryWordExpression.expression, sourceFile);
|
||||
|
||||
case SyntaxKind.TaggedTemplateExpression:
|
||||
@@ -1282,7 +1282,7 @@ namespace ts {
|
||||
if (isImportOrExportSpecifierName(location)) {
|
||||
return location.getText();
|
||||
}
|
||||
else if (isStringOrNumericLiteral(location.kind) &&
|
||||
else if (isStringOrNumericLiteral(location) &&
|
||||
location.parent.kind === SyntaxKind.ComputedPropertyName) {
|
||||
return (<LiteralExpression>location).text;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
//// [alwaysStrictModule3.ts]
|
||||
|
||||
// module ES2015
|
||||
export const a = 1;
|
||||
|
||||
//// [alwaysStrictModule3.js]
|
||||
// module ES2015
|
||||
export var a = 1;
|
||||
@@ -0,0 +1,6 @@
|
||||
=== tests/cases/compiler/alwaysStrictModule3.ts ===
|
||||
|
||||
// module ES2015
|
||||
export const a = 1;
|
||||
>a : Symbol(a, Decl(alwaysStrictModule3.ts, 2, 12))
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
=== tests/cases/compiler/alwaysStrictModule3.ts ===
|
||||
|
||||
// module ES2015
|
||||
export const a = 1;
|
||||
>a : 1
|
||||
>1 : 1
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
//// [alwaysStrictModule4.ts]
|
||||
|
||||
// Module commonjs
|
||||
export const a = 1
|
||||
|
||||
//// [alwaysStrictModule4.js]
|
||||
"use strict";
|
||||
// Module commonjs
|
||||
exports.a = 1;
|
||||
@@ -0,0 +1,6 @@
|
||||
=== tests/cases/compiler/alwaysStrictModule4.ts ===
|
||||
|
||||
// Module commonjs
|
||||
export const a = 1
|
||||
>a : Symbol(a, Decl(alwaysStrictModule4.ts, 2, 12))
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
=== tests/cases/compiler/alwaysStrictModule4.ts ===
|
||||
|
||||
// Module commonjs
|
||||
export const a = 1
|
||||
>a : 1
|
||||
>1 : 1
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
//// [alwaysStrictModule5.ts]
|
||||
|
||||
// Targeting ES6
|
||||
export const a = 1;
|
||||
|
||||
//// [alwaysStrictModule5.js]
|
||||
// Targeting ES6
|
||||
export const a = 1;
|
||||
@@ -0,0 +1,6 @@
|
||||
=== tests/cases/compiler/alwaysStrictModule5.ts ===
|
||||
|
||||
// Targeting ES6
|
||||
export const a = 1;
|
||||
>a : Symbol(a, Decl(alwaysStrictModule5.ts, 2, 12))
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
=== tests/cases/compiler/alwaysStrictModule5.ts ===
|
||||
|
||||
// Targeting ES6
|
||||
export const a = 1;
|
||||
>a : 1
|
||||
>1 : 1
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
//// [alwaysStrictModule6.ts]
|
||||
|
||||
// Targeting ES5
|
||||
export const a = 1;
|
||||
|
||||
//// [alwaysStrictModule6.js]
|
||||
"use strict";
|
||||
// Targeting ES5
|
||||
exports.a = 1;
|
||||
@@ -0,0 +1,6 @@
|
||||
=== tests/cases/compiler/alwaysStrictModule6.ts ===
|
||||
|
||||
// Targeting ES5
|
||||
export const a = 1;
|
||||
>a : Symbol(a, Decl(alwaysStrictModule6.ts, 2, 12))
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
=== tests/cases/compiler/alwaysStrictModule6.ts ===
|
||||
|
||||
// Targeting ES5
|
||||
export const a = 1;
|
||||
>a : 1
|
||||
>1 : 1
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
tests/cases/compiler/ambientWithStatements.ts(2,5): error TS1036: Statements are not allowed in ambient contexts.
|
||||
tests/cases/compiler/ambientWithStatements.ts(3,5): error TS1104: A 'continue' statement can only be used within an enclosing iteration statement.
|
||||
tests/cases/compiler/ambientWithStatements.ts(3,5): error TS1105: A 'continue' statement can only be used within an enclosing iteration statement.
|
||||
tests/cases/compiler/ambientWithStatements.ts(7,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter.
|
||||
tests/cases/compiler/ambientWithStatements.ts(11,5): error TS1108: A 'return' statement can only be used within a function body.
|
||||
tests/cases/compiler/ambientWithStatements.ts(25,5): error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
|
||||
@@ -12,7 +12,7 @@ tests/cases/compiler/ambientWithStatements.ts(25,5): error TS2410: The 'with' st
|
||||
!!! error TS1036: Statements are not allowed in ambient contexts.
|
||||
continue;
|
||||
~~~~~~~~~
|
||||
!!! error TS1104: A 'continue' statement can only be used within an enclosing iteration statement.
|
||||
!!! error TS1105: A 'continue' statement can only be used within an enclosing iteration statement.
|
||||
debugger;
|
||||
do { } while (true);
|
||||
var x;
|
||||
|
||||
@@ -2,4 +2,8 @@
|
||||
var v = async function await(): Promise<void> { }
|
||||
|
||||
//// [asyncFunctionDeclaration12_es5.js]
|
||||
var v = , await = function () { };
|
||||
var v = function () {
|
||||
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
|
||||
return [2 /*return*/];
|
||||
}); });
|
||||
}, await = function () { };
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user