Skip to content

Commit 989f9d8

Browse files
author
Kanchalai Tanglertsampan
committed
Merge branch 'master' into wip-master-statelessOverload
2 parents bcba51d + feb08b8 commit 989f9d8

22 files changed

+476
-104
lines changed

Gulpfile.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ const cmdLineOptions = minimist(process.argv.slice(2), {
5050
r: "reporter",
5151
color: "colors",
5252
f: "files",
53-
file: "files"
53+
file: "files",
54+
w: "workers",
5455
},
5556
default: {
5657
soft: false,
@@ -63,6 +64,7 @@ const cmdLineOptions = minimist(process.argv.slice(2), {
6364
reporter: process.env.reporter || process.env.r,
6465
lint: process.env.lint || true,
6566
files: process.env.f || process.env.file || process.env.files || "",
67+
workers: process.env.workerCount || os.cpus().length,
6668
}
6769
});
6870

@@ -604,7 +606,7 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done:
604606
} while (fs.existsSync(taskConfigsFolder));
605607
fs.mkdirSync(taskConfigsFolder);
606608

607-
workerCount = process.env.workerCount || os.cpus().length;
609+
workerCount = cmdLineOptions["workers"];
608610
}
609611

610612
if (tests || light || taskConfigsFolder) {
@@ -1017,7 +1019,7 @@ gulp.task("lint", "Runs tslint on the compiler sources. Optional arguments are:
10171019
cb();
10181020
}, (cb) => {
10191021
files = files.filter(file => fileMatcher.test(file.path)).sort((filea, fileb) => filea.stat.size - fileb.stat.size);
1020-
const workerCount = (process.env.workerCount && +process.env.workerCount) || os.cpus().length;
1022+
const workerCount = cmdLineOptions["workers"];
10211023
for (let i = 0; i < workerCount; i++) {
10221024
spawnLintWorker(files, finished);
10231025
}

src/compiler/binder.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,7 +1514,7 @@ namespace ts {
15141514
errorOnFirstToken(node, Diagnostics.export_modifier_cannot_be_applied_to_ambient_modules_and_module_augmentations_since_they_are_always_visible);
15151515
}
15161516
if (isExternalModuleAugmentation(node)) {
1517-
declareSymbolAndAddToSymbolTable(node, SymbolFlags.NamespaceModule, SymbolFlags.NamespaceModuleExcludes);
1517+
declareModuleSymbol(node);
15181518
}
15191519
else {
15201520
let pattern: Pattern | undefined;
@@ -1536,12 +1536,8 @@ namespace ts {
15361536
}
15371537
}
15381538
else {
1539-
const state = getModuleInstanceState(node);
1540-
if (state === ModuleInstanceState.NonInstantiated) {
1541-
declareSymbolAndAddToSymbolTable(node, SymbolFlags.NamespaceModule, SymbolFlags.NamespaceModuleExcludes);
1542-
}
1543-
else {
1544-
declareSymbolAndAddToSymbolTable(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes);
1539+
const state = declareModuleSymbol(node);
1540+
if (state !== ModuleInstanceState.NonInstantiated) {
15451541
if (node.symbol.flags & (SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.RegularEnum)) {
15461542
// if module was already merged with some function, class or non-const enum
15471543
// treat is a non-const-enum-only
@@ -1562,6 +1558,15 @@ namespace ts {
15621558
}
15631559
}
15641560

1561+
function declareModuleSymbol(node: ModuleDeclaration): ModuleInstanceState {
1562+
const state = getModuleInstanceState(node);
1563+
const instantiated = state !== ModuleInstanceState.NonInstantiated;
1564+
declareSymbolAndAddToSymbolTable(node,
1565+
instantiated ? SymbolFlags.ValueModule : SymbolFlags.NamespaceModule,
1566+
instantiated ? SymbolFlags.ValueModuleExcludes : SymbolFlags.NamespaceModuleExcludes);
1567+
return state;
1568+
}
1569+
15651570
function bindFunctionOrConstructorType(node: SignatureDeclaration): void {
15661571
// For a given function symbol "<...>(...) => T" we want to generate a symbol identical
15671572
// to the one we would get for: { <...>(...): T }

src/compiler/checker.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,9 @@ namespace ts {
486486
}
487487
recordMergedSymbol(target, source);
488488
}
489+
else if (target.flags & SymbolFlags.NamespaceModule) {
490+
error(source.valueDeclaration.name, Diagnostics.Cannot_augment_module_0_with_value_exports_because_it_resolves_to_a_non_module_entity, symbolToString(target));
491+
}
489492
else {
490493
const message = target.flags & SymbolFlags.BlockScopedVariable || source.flags & SymbolFlags.BlockScopedVariable
491494
? Diagnostics.Cannot_redeclare_block_scoped_variable_0 : Diagnostics.Duplicate_identifier_0;

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,6 +1823,10 @@
18231823
"category": "Error",
18241824
"code": 2609
18251825
},
1826+
"Cannot augment module '{0}' with value exports because it resolves to a non-module entity.": {
1827+
"category": "Error",
1828+
"code": 2649
1829+
},
18261830
"Cannot emit namespaced JSX elements in React": {
18271831
"category": "Error",
18281832
"code": 2650

src/compiler/transformers/es2015.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2316,7 +2316,7 @@ namespace ts {
23162316
addRange(statements, convertedLoopBodyStatements);
23172317
}
23182318
else {
2319-
const statement = visitNode(node.statement, visitor, isStatement);
2319+
const statement = visitNode(node.statement, visitor, isStatement, /*optional*/ false, liftToBlock);
23202320
if (isBlock(statement)) {
23212321
addRange(statements, statement.statements);
23222322
bodyLocation = statement;

src/server/session.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -484,18 +484,20 @@ namespace ts.server {
484484

485485
private getImplementation(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): protocol.FileSpan[] | ImplementationLocation[] {
486486
const { file, project } = this.getFileAndProject(args);
487-
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
488-
const position = this.getPosition(args, scriptInfo);
487+
const position = this.getPosition(args, project.getScriptInfoForNormalizedPath(file));
489488
const implementations = project.getLanguageService().getImplementationAtPosition(file, position);
490489
if (!implementations) {
491490
return [];
492491
}
493492
if (simplifiedResult) {
494-
return implementations.map(impl => ({
495-
file: impl.fileName,
496-
start: scriptInfo.positionToLineOffset(impl.textSpan.start),
497-
end: scriptInfo.positionToLineOffset(ts.textSpanEnd(impl.textSpan))
498-
}));
493+
return implementations.map(({ fileName, textSpan }) => {
494+
const scriptInfo = project.getScriptInfo(fileName);
495+
return {
496+
file: fileName,
497+
start: scriptInfo.positionToLineOffset(textSpan.start),
498+
end: scriptInfo.positionToLineOffset(ts.textSpanEnd(textSpan))
499+
};
500+
});
499501
}
500502
else {
501503
return implementations;

src/services/goToDefinition.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,15 @@ namespace ts.GoToDefinition {
220220
}
221221

222222
function isSignatureDeclaration(node: Node): boolean {
223-
return node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature
223+
switch (node.kind) {
224+
case ts.SyntaxKind.Constructor:
225+
case ts.SyntaxKind.FunctionDeclaration:
226+
case ts.SyntaxKind.MethodDeclaration:
227+
case ts.SyntaxKind.MethodSignature:
228+
return true;
229+
default:
230+
return false;
231+
}
224232
}
225233

226234
/** Creates a DefinitionInfo from a Declaration, using the declaration's name if possible. */
@@ -287,11 +295,16 @@ namespace ts.GoToDefinition {
287295

288296
function tryGetSignatureDeclaration(typeChecker: TypeChecker, node: Node): SignatureDeclaration | undefined {
289297
const callLike = getAncestorCallLikeExpression(node);
290-
if (callLike) {
291-
const resolvedSignature = typeChecker.getResolvedSignature(callLike);
298+
const signature = callLike && typeChecker.getResolvedSignature(callLike);
299+
if (signature) {
300+
const decl = signature.declaration;
292301
// We have to check that resolvedSignature is not undefined because in the case of JSX opening-like element,
293302
// it may not be a stateless function component which then will cause getResolvedSignature to return undefined.
294-
return resolvedSignature && resolvedSignature.declaration;
303+
if (decl && isSignatureDeclaration(decl)) {
304+
return decl;
305+
}
295306
}
307+
// Don't go to a function type, go to the value having that type.
308+
return undefined;
296309
}
297310
}

src/services/rename.ts

Lines changed: 74 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,92 @@
11
/* @internal */
22
namespace ts.Rename {
33
export function getRenameInfo(typeChecker: TypeChecker, defaultLibFileName: string, getCanonicalFileName: (fileName: string) => string, sourceFile: SourceFile, position: number): RenameInfo {
4-
const canonicalDefaultLibName = getCanonicalFileName(ts.normalizePath(defaultLibFileName));
5-
4+
const getCanonicalDefaultLibName = memoize(() => getCanonicalFileName(ts.normalizePath(defaultLibFileName)));
65
const node = getTouchingWord(sourceFile, position, /*includeJsDocComment*/ true);
6+
const renameInfo = node && nodeIsEligibleForRename(node)
7+
? getRenameInfoForNode(node, typeChecker, sourceFile, isDefinedInLibraryFile)
8+
: undefined;
9+
return renameInfo || getRenameInfoError(Diagnostics.You_cannot_rename_this_element);
710

8-
if (node) {
9-
if (node.kind === SyntaxKind.Identifier ||
10-
node.kind === SyntaxKind.StringLiteral ||
11-
isLiteralNameOfPropertyDeclarationOrIndexAccess(node) ||
12-
isThis(node)) {
13-
const symbol = typeChecker.getSymbolAtLocation(node);
11+
function isDefinedInLibraryFile(declaration: Node) {
12+
if (!defaultLibFileName) {
13+
return false;
14+
}
15+
16+
const sourceFile = declaration.getSourceFile();
17+
const canonicalName = getCanonicalFileName(ts.normalizePath(sourceFile.fileName));
18+
return canonicalName === getCanonicalDefaultLibName();
19+
}
20+
}
1421

15-
// Only allow a symbol to be renamed if it actually has at least one declaration.
16-
if (symbol) {
17-
const declarations = symbol.getDeclarations();
18-
if (declarations && declarations.length > 0) {
19-
// Disallow rename for elements that are defined in the standard TypeScript library.
20-
if (forEach(declarations, isDefinedInLibraryFile)) {
21-
return getRenameInfoError(getLocaleSpecificMessage(Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library));
22-
}
22+
function getRenameInfoForNode(node: Node, typeChecker: TypeChecker, sourceFile: SourceFile, isDefinedInLibraryFile: (declaration: Node) => boolean): RenameInfo | undefined {
23+
const symbol = typeChecker.getSymbolAtLocation(node);
2324

24-
const displayName = stripQuotes(getDeclaredName(typeChecker, symbol, node));
25-
const kind = SymbolDisplay.getSymbolKind(typeChecker, symbol, node);
26-
if (kind) {
27-
return {
28-
canRename: true,
29-
kind,
30-
displayName,
31-
localizedErrorMessage: undefined,
32-
fullDisplayName: typeChecker.getFullyQualifiedName(symbol),
33-
kindModifiers: SymbolDisplay.getSymbolModifiers(symbol),
34-
triggerSpan: createTriggerSpanForNode(node, sourceFile)
35-
};
36-
}
37-
}
25+
// Only allow a symbol to be renamed if it actually has at least one declaration.
26+
if (symbol) {
27+
const declarations = symbol.getDeclarations();
28+
if (declarations && declarations.length > 0) {
29+
// Disallow rename for elements that are defined in the standard TypeScript library.
30+
if (some(declarations, isDefinedInLibraryFile)) {
31+
return getRenameInfoError(Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library);
3832
}
39-
else if (node.kind === SyntaxKind.StringLiteral) {
40-
const type = getStringLiteralTypeForNode(<StringLiteral>node, typeChecker);
41-
if (type) {
42-
if (isDefinedInLibraryFile(node)) {
43-
return getRenameInfoError(getLocaleSpecificMessage(Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library));
44-
}
45-
else {
46-
const displayName = stripQuotes(type.text);
47-
return {
48-
canRename: true,
49-
kind: ScriptElementKind.variableElement,
50-
displayName,
51-
localizedErrorMessage: undefined,
52-
fullDisplayName: displayName,
53-
kindModifiers: ScriptElementKindModifier.none,
54-
triggerSpan: createTriggerSpanForNode(node, sourceFile)
55-
};
56-
}
57-
}
33+
34+
const displayName = stripQuotes(getDeclaredName(typeChecker, symbol, node));
35+
const kind = SymbolDisplay.getSymbolKind(typeChecker, symbol, node);
36+
return kind ? getRenameInfoSuccess(displayName, typeChecker.getFullyQualifiedName(symbol), kind, SymbolDisplay.getSymbolModifiers(symbol), node, sourceFile) : undefined;
37+
}
38+
}
39+
else if (node.kind === SyntaxKind.StringLiteral) {
40+
const type = getStringLiteralTypeForNode(<StringLiteral>node, typeChecker);
41+
if (type) {
42+
if (isDefinedInLibraryFile(node)) {
43+
return getRenameInfoError(Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library);
5844
}
45+
46+
const displayName = stripQuotes(type.text);
47+
return getRenameInfoSuccess(displayName, displayName, ScriptElementKind.variableElement, ScriptElementKindModifier.none, node, sourceFile);
5948
}
6049
}
50+
}
6151

62-
return getRenameInfoError(getLocaleSpecificMessage(Diagnostics.You_cannot_rename_this_element));
52+
function getRenameInfoSuccess(displayName: string, fullDisplayName: string, kind: string, kindModifiers: string, node: Node, sourceFile: SourceFile): RenameInfo {
53+
return {
54+
canRename: true,
55+
kind,
56+
displayName,
57+
localizedErrorMessage: undefined,
58+
fullDisplayName,
59+
kindModifiers,
60+
triggerSpan: createTriggerSpanForNode(node, sourceFile)
61+
};
62+
}
6363

64-
function getRenameInfoError(localizedErrorMessage: string): RenameInfo {
65-
return {
66-
canRename: false,
67-
localizedErrorMessage: localizedErrorMessage,
68-
displayName: undefined,
69-
fullDisplayName: undefined,
70-
kind: undefined,
71-
kindModifiers: undefined,
72-
triggerSpan: undefined
73-
};
74-
}
64+
function getRenameInfoError(diagnostic: DiagnosticMessage): RenameInfo {
65+
return {
66+
canRename: false,
67+
localizedErrorMessage: getLocaleSpecificMessage(diagnostic),
68+
displayName: undefined,
69+
fullDisplayName: undefined,
70+
kind: undefined,
71+
kindModifiers: undefined,
72+
triggerSpan: undefined
73+
};
74+
}
7575

76-
function isDefinedInLibraryFile(declaration: Node) {
77-
if (defaultLibFileName) {
78-
const sourceFile = declaration.getSourceFile();
79-
const canonicalName = getCanonicalFileName(ts.normalizePath(sourceFile.fileName));
80-
if (canonicalName === canonicalDefaultLibName) {
81-
return true;
82-
}
83-
}
84-
return false;
76+
function createTriggerSpanForNode(node: Node, sourceFile: SourceFile) {
77+
let start = node.getStart(sourceFile);
78+
let width = node.getWidth(sourceFile);
79+
if (node.kind === SyntaxKind.StringLiteral) {
80+
// Exclude the quotes
81+
start += 1;
82+
width -= 2;
8583
}
84+
return createTextSpan(start, width);
85+
}
8686

87-
function createTriggerSpanForNode(node: Node, sourceFile: SourceFile) {
88-
let start = node.getStart(sourceFile);
89-
let width = node.getWidth(sourceFile);
90-
if (node.kind === SyntaxKind.StringLiteral) {
91-
// Exclude the quotes
92-
start += 1;
93-
width -= 2;
94-
}
95-
return createTextSpan(start, width);
96-
}
87+
function nodeIsEligibleForRename(node: Node) {
88+
return node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.StringLiteral ||
89+
isLiteralNameOfPropertyDeclarationOrIndexAccess(node) ||
90+
isThis(node);
9791
}
9892
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/node_modules/@types/lib-extender/index.d.ts(2,16): error TS2649: Cannot augment module 'lib' with value exports because it resolves to a non-module entity.
2+
3+
4+
==== /node_modules/lib/index.d.ts (0 errors) ====
5+
declare var lib: () => void;
6+
declare namespace lib {}
7+
export = lib;
8+
9+
==== /node_modules/@types/lib-extender/index.d.ts (1 errors) ====
10+
import * as lib from "lib";
11+
declare module "lib" {
12+
~~~~~
13+
!!! error TS2649: Cannot augment module 'lib' with value exports because it resolves to a non-module entity.
14+
export function fn(): void;
15+
}
16+

tests/baselines/reference/globalAugmentationModuleResolution.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
export { };
44

55
declare global {
6-
>global : any
6+
>global : typeof global
77

88
var x: number;
99
>x : number

0 commit comments

Comments
 (0)