Skip to content

Commit c22730e

Browse files
committed
Merge branch 'master' into publicTransformers
2 parents fc2cf2f + 0a1d75d commit c22730e

File tree

88 files changed

+600
-912
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+600
-912
lines changed

Jakefile.js

Lines changed: 32 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ var path = require("path");
66
var child_process = require("child_process");
77
var fold = require("travis-fold");
88
var runTestsInParallel = require("./scripts/mocha-parallel").runTestsInParallel;
9+
var ts = require("./lib/typescript");
10+
911

1012
// Variables
1113
var compilerDirectory = "src/compiler/";
@@ -34,6 +36,25 @@ if (process.env.path !== undefined) {
3436
process.env.PATH = nodeModulesPathPrefix + process.env.PATH;
3537
}
3638

39+
function filesFromConfig(configPath) {
40+
console.log(configPath);
41+
var configText = fs.readFileSync(configPath).toString();
42+
var config = ts.parseConfigFileTextToJson(configPath, configText, /*stripComments*/ true);
43+
if (config.error) {
44+
throw new Error(diagnosticsToString([config.error]));
45+
}
46+
const configFileContent = ts.parseJsonConfigFileContent(config.config, ts.sys, path.dirname(configPath));
47+
if (configFileContent.errors && configFileContent.errors.length) {
48+
throw new Error(diagnosticsToString(configFileContent.errors));
49+
}
50+
51+
return configFileContent.fileNames;
52+
53+
function diagnosticsToString(s) {
54+
return s.map(function(e) { return ts.flattenDiagnosticMessageText(e.messageText, ts.sys.newLine); }).join(ts.sys.newLine);
55+
}
56+
}
57+
3758
function toNs(diff) {
3859
return diff[0] * 1e9 + diff[1];
3960
}
@@ -56,174 +77,12 @@ function measure(marker) {
5677
console.log("travis_time:end:" + marker.id + ":start=" + toNs(marker.stamp) + ",finish=" + toNs(total) + ",duration=" + toNs(diff) + "\r");
5778
}
5879

59-
var compilerSources = [
60-
"core.ts",
61-
"performance.ts",
62-
"sys.ts",
63-
"types.ts",
64-
"scanner.ts",
65-
"parser.ts",
66-
"utilities.ts",
67-
"binder.ts",
68-
"checker.ts",
69-
"factory.ts",
70-
"visitor.ts",
71-
"transformers/destructuring.ts",
72-
"transformers/ts.ts",
73-
"transformers/jsx.ts",
74-
"transformers/esnext.ts",
75-
"transformers/es2017.ts",
76-
"transformers/es2016.ts",
77-
"transformers/es2015.ts",
78-
"transformers/generators.ts",
79-
"transformers/es5.ts",
80-
"transformers/module/es2015.ts",
81-
"transformers/module/system.ts",
82-
"transformers/module/module.ts",
83-
"transformer.ts",
84-
"sourcemap.ts",
85-
"comments.ts",
86-
"declarationEmitter.ts",
87-
"emitter.ts",
88-
"program.ts",
89-
"commandLineParser.ts",
90-
"tsc.ts",
91-
"diagnosticInformationMap.generated.ts"
92-
].map(function (f) {
93-
return path.join(compilerDirectory, f);
94-
});
95-
96-
var servicesSources = [
97-
"core.ts",
98-
"performance.ts",
99-
"sys.ts",
100-
"types.ts",
101-
"scanner.ts",
102-
"parser.ts",
103-
"utilities.ts",
104-
"binder.ts",
105-
"checker.ts",
106-
"factory.ts",
107-
"visitor.ts",
108-
"transformers/destructuring.ts",
109-
"transformers/ts.ts",
110-
"transformers/jsx.ts",
111-
"transformers/esnext.ts",
112-
"transformers/es2017.ts",
113-
"transformers/es2016.ts",
114-
"transformers/es2015.ts",
115-
"transformers/generators.ts",
116-
"transformers/es5.ts",
117-
"transformers/module/es2015.ts",
118-
"transformers/module/system.ts",
119-
"transformers/module/module.ts",
120-
"transformer.ts",
121-
"sourcemap.ts",
122-
"comments.ts",
123-
"declarationEmitter.ts",
124-
"emitter.ts",
125-
"program.ts",
126-
"commandLineParser.ts",
127-
"diagnosticInformationMap.generated.ts"
128-
].map(function (f) {
129-
return path.join(compilerDirectory, f);
130-
}).concat([
131-
"types.ts",
132-
"utilities.ts",
133-
"breakpoints.ts",
134-
"classifier.ts",
135-
"completions.ts",
136-
"documentHighlights.ts",
137-
"documentRegistry.ts",
138-
"findAllReferences.ts",
139-
"goToDefinition.ts",
140-
"goToImplementation.ts",
141-
"jsDoc.ts",
142-
"jsTyping.ts",
143-
"navigateTo.ts",
144-
"navigationBar.ts",
145-
"outliningElementsCollector.ts",
146-
"patternMatcher.ts",
147-
"preProcess.ts",
148-
"rename.ts",
149-
"services.ts",
150-
"shims.ts",
151-
"signatureHelp.ts",
152-
"symbolDisplay.ts",
153-
"transform.ts",
154-
"transpile.ts",
155-
// Formatting
156-
"formatting/formatting.ts",
157-
"formatting/formattingContext.ts",
158-
"formatting/formattingRequestKind.ts",
159-
"formatting/formattingScanner.ts",
160-
"formatting/references.ts",
161-
"formatting/rule.ts",
162-
"formatting/ruleAction.ts",
163-
"formatting/ruleDescriptor.ts",
164-
"formatting/ruleFlag.ts",
165-
"formatting/ruleOperation.ts",
166-
"formatting/ruleOperationContext.ts",
167-
"formatting/rules.ts",
168-
"formatting/rulesMap.ts",
169-
"formatting/rulesProvider.ts",
170-
"formatting/smartIndenter.ts",
171-
"formatting/tokenRange.ts",
172-
// CodeFixes
173-
"codeFixProvider.ts",
174-
"codefixes/fixes.ts",
175-
"codefixes/fixExtendsInterfaceBecomesImplements.ts",
176-
"codefixes/fixClassIncorrectlyImplementsInterface.ts",
177-
"codefixes/fixClassDoesntImplementInheritedAbstractMember.ts",
178-
"codefixes/fixClassSuperMustPrecedeThisAccess.ts",
179-
"codefixes/fixConstructorForDerivedNeedSuperCall.ts",
180-
"codefixes/helpers.ts",
181-
"codefixes/importFixes.ts",
182-
"codefixes/unusedIdentifierFixes.ts"
183-
].map(function (f) {
184-
return path.join(servicesDirectory, f);
185-
}));
186-
187-
var baseServerCoreSources = [
188-
"builder.ts",
189-
"editorServices.ts",
190-
"lsHost.ts",
191-
"project.ts",
192-
"protocol.ts",
193-
"scriptInfo.ts",
194-
"scriptVersionCache.ts",
195-
"session.ts",
196-
"shared.ts",
197-
"types.ts",
198-
"typingsCache.ts",
199-
"utilities.ts",
200-
].map(function (f) {
201-
return path.join(serverDirectory, f);
202-
});
203-
204-
var serverCoreSources = [
205-
"server.ts"
206-
].map(function (f) {
207-
return path.join(serverDirectory, f);
208-
}).concat(baseServerCoreSources);
209-
210-
var cancellationTokenSources = [
211-
"cancellationToken.ts"
212-
].map(function (f) {
213-
return path.join(cancellationTokenDirectory, f);
214-
});
215-
216-
var typingsInstallerSources = [
217-
"../types.ts",
218-
"../shared.ts",
219-
"typingsInstaller.ts",
220-
"nodeTypingsInstaller.ts"
221-
].map(function (f) {
222-
return path.join(typingsInstallerDirectory, f);
223-
});
224-
225-
var serverSources = serverCoreSources.concat(servicesSources);
226-
var languageServiceLibrarySources = baseServerCoreSources.concat(servicesSources);
80+
var compilerSources = filesFromConfig("./src/compiler/tsconfig.json");
81+
var servicesSources = filesFromConfig("./src/services/tsconfig.json");
82+
var cancellationTokenSources = filesFromConfig(path.join(serverDirectory, "cancellationToken/tsconfig.json"));
83+
var typingsInstallerSources = filesFromConfig(path.join(serverDirectory, "typingsInstaller/tsconfig.json"));
84+
var serverSources = filesFromConfig(path.join(serverDirectory, "tsconfig.json"))
85+
var languageServiceLibrarySources = filesFromConfig(path.join(serverDirectory, "tsconfig.library.json"));
22786

22887
var harnessCoreSources = [
22988
"harness.ts",
@@ -1255,13 +1114,16 @@ var lintTargets = compilerSources
12551114
.concat(harnessSources)
12561115
// Other harness sources
12571116
.concat(["instrumenter.ts"].map(function (f) { return path.join(harnessDirectory, f) }))
1258-
.concat(serverCoreSources)
1117+
.concat(serverSources)
12591118
.concat(tslintRulesFiles)
12601119
.concat(servicesSources)
12611120
.concat(typingsInstallerSources)
12621121
.concat(cancellationTokenSources)
12631122
.concat(["Gulpfile.ts"])
1264-
.concat([nodeServerInFile, perftscPath, "tests/perfsys.ts", webhostPath]);
1123+
.concat([nodeServerInFile, perftscPath, "tests/perfsys.ts", webhostPath])
1124+
.map(function (p) { return path.resolve(p) });
1125+
// keep only unique items
1126+
lintTargets = Array.from(new Set(lintTargets));
12651127

12661128
function sendNextFile(files, child, callback, failures) {
12671129
var file = files.pop();

src/compiler/checker.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,6 @@ namespace ts {
389389
"object": TypeFacts.TypeofEQObject,
390390
"function": TypeFacts.TypeofEQFunction
391391
});
392-
393392
const typeofNEFacts = createMapFromTemplate({
394393
"string": TypeFacts.TypeofNEString,
395394
"number": TypeFacts.TypeofNENumber,
@@ -399,14 +398,14 @@ namespace ts {
399398
"object": TypeFacts.TypeofNEObject,
400399
"function": TypeFacts.TypeofNEFunction
401400
});
402-
403401
const typeofTypesByName = createMapFromTemplate<Type>({
404402
"string": stringType,
405403
"number": numberType,
406404
"boolean": booleanType,
407405
"symbol": esSymbolType,
408406
"undefined": undefinedType
409407
});
408+
const typeofType = createTypeofType();
410409

411410
let jsxElementType: Type;
412411
let _jsxNamespace: string;
@@ -1790,6 +1789,10 @@ namespace ts {
17901789
return type;
17911790
}
17921791

1792+
function createTypeofType() {
1793+
return getUnionType(convertToArray(typeofEQFacts.keys(), s => getLiteralTypeForText(TypeFlags.StringLiteral, s)));
1794+
}
1795+
17931796
// A reserved member name starts with two underscores, but the third character cannot be an underscore
17941797
// or the @ symbol. A third underscore indicates an escaped form of an identifer that started
17951798
// with at least two underscores. The @ character indicates that the name is denoted by a well known ES
@@ -14689,7 +14692,7 @@ namespace ts {
1468914692

1469014693
function checkTypeOfExpression(node: TypeOfExpression): Type {
1469114694
checkExpression(node.expression);
14692-
return stringType;
14695+
return typeofType;
1469314696
}
1469414697

1469514698
function checkVoidExpression(node: VoidExpression): Type {

src/compiler/core.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,14 @@ namespace ts {
895895
return result;
896896
}
897897

898+
export function convertToArray<T, U>(iterator: Iterator<T>, f: (value: T) => U) {
899+
const result: U[] = [];
900+
for (let { value, done } = iterator.next(); !done; { value, done } = iterator.next()) {
901+
result.push(f(value));
902+
}
903+
return result;
904+
}
905+
898906
/**
899907
* Calls `callback` for each entry in the map, returning the first truthy result.
900908
* Use `map.forEach` instead for normal iteration.

src/compiler/sys.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,10 @@ namespace ts {
485485
// Node 4.0 `fs.watch` function supports the "recursive" option on both OSX and Windows
486486
// (ref: https://github.com/nodejs/node/pull/2649 and https://github.com/Microsoft/TypeScript/issues/4643)
487487
let options: any;
488-
if (!directoryExists(directoryName)) {
488+
if (!directoryExists(directoryName) || (isUNCPath(directoryName) && process.platform === "win32")) {
489+
// do nothing if either
490+
// - target folder does not exist
491+
// - this is UNC path on Windows (https://github.com/Microsoft/TypeScript/issues/13874)
489492
return noOpFileWatcher;
490493
}
491494

@@ -509,6 +512,10 @@ namespace ts {
509512
};
510513
}
511514
);
515+
516+
function isUNCPath(s: string): boolean {
517+
return s.length > 2 && s.charCodeAt(0) === CharacterCodes.slash && s.charCodeAt(1) === CharacterCodes.slash;
518+
}
512519
},
513520
resolvePath: function(path: string): string {
514521
return _path.resolve(path);

tests/baselines/reference/TypeGuardWithEnumUnion.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function f1(x: Color | string) {
1212

1313
if (typeof x === "number") {
1414
>typeof x === "number" : boolean
15-
>typeof x : string
15+
>typeof x : "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function"
1616
>x : string | Color
1717
>"number" : "number"
1818

@@ -41,7 +41,7 @@ function f2(x: Color | string | string[]) {
4141

4242
if (typeof x === "object") {
4343
>typeof x === "object" : boolean
44-
>typeof x : string
44+
>typeof x : "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function"
4545
>x : string | Color | string[]
4646
>"object" : "object"
4747

@@ -54,7 +54,7 @@ function f2(x: Color | string | string[]) {
5454
}
5555
if (typeof x === "number") {
5656
>typeof x === "number" : boolean
57-
>typeof x : string
57+
>typeof x : "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function"
5858
>x : string | Color | string[]
5959
>"number" : "number"
6060

@@ -76,7 +76,7 @@ function f2(x: Color | string | string[]) {
7676
}
7777
if (typeof x === "string") {
7878
>typeof x === "string" : boolean
79-
>typeof x : string
79+
>typeof x : "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function"
8080
>x : string | Color | string[]
8181
>"string" : "string"
8282

tests/baselines/reference/anonymousClassExpression1.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function f() {
44

55
return typeof class {} === "function";
66
>typeof class {} === "function" : boolean
7-
>typeof class {} : string
7+
>typeof class {} : "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function"
88
>class {} : typeof (Anonymous class)
99
>"function" : "function"
1010
}

tests/baselines/reference/callSignatureWithoutReturnTypeAnnotationInference.types

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,17 @@ var r6 = foo6(1);
103103
>1 : 1
104104

105105
function foo7(x) {
106-
>foo7 : (x: any) => string
106+
>foo7 : (x: any) => "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function"
107107
>x : any
108108

109109
return typeof x;
110-
>typeof x : string
110+
>typeof x : "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function"
111111
>x : any
112112
}
113113
var r7 = foo7(1);
114-
>r7 : string
115-
>foo7(1) : string
116-
>foo7 : (x: any) => string
114+
>r7 : "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function"
115+
>foo7(1) : "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function"
116+
>foo7 : (x: any) => "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function"
117117
>1 : 1
118118

119119
// object types

tests/baselines/reference/castExpressionParentheses.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ declare var A;
182182
>(<any>typeof A).x : any
183183
>(<any>typeof A) : any
184184
><any>typeof A : any
185-
>typeof A : string
185+
>typeof A : "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function"
186186
>A : any
187187
>x : any
188188

0 commit comments

Comments
 (0)