Skip to content

Commit 1763db4

Browse files
committed
Merge remote-tracking branch 'origin/master' into far_display_parts
2 parents 4c847eb + 712e7bf commit 1763db4

32 files changed

+302
-53
lines changed

src/compiler/checker.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,8 +1023,8 @@ namespace ts {
10231023
}
10241024
}
10251025

1026-
function getDeclarationOfAliasSymbol(symbol: Symbol): Declaration {
1027-
return findMap(symbol.declarations, d => isAliasSymbolDeclaration(d) ? d : undefined);
1026+
function getDeclarationOfAliasSymbol(symbol: Symbol): Declaration | undefined {
1027+
return forEach(symbol.declarations, d => isAliasSymbolDeclaration(d) ? d : undefined);
10281028
}
10291029

10301030
function getTargetOfImportEqualsDeclaration(node: ImportEqualsDeclaration): Symbol {
@@ -1191,6 +1191,7 @@ namespace ts {
11911191
if (!links.target) {
11921192
links.target = resolvingSymbol;
11931193
const node = getDeclarationOfAliasSymbol(symbol);
1194+
Debug.assert(!!node);
11941195
const target = getTargetOfAliasDeclaration(node);
11951196
if (links.target === resolvingSymbol) {
11961197
links.target = target || unknownSymbol;
@@ -1226,6 +1227,7 @@ namespace ts {
12261227
if (!links.referenced) {
12271228
links.referenced = true;
12281229
const node = getDeclarationOfAliasSymbol(symbol);
1230+
Debug.assert(!!node);
12291231
if (node.kind === SyntaxKind.ExportAssignment) {
12301232
// export default <symbol>
12311233
checkExpressionCached((<ExportAssignment>node).expression);
@@ -18761,7 +18763,13 @@ namespace ts {
1876118763
(augmentations || (augmentations = [])).push(file.moduleAugmentations);
1876218764
}
1876318765
if (file.symbol && file.symbol.globalExports) {
18764-
mergeSymbolTable(globals, file.symbol.globalExports);
18766+
// Merge in UMD exports with first-in-wins semantics (see #9771)
18767+
const source = file.symbol.globalExports;
18768+
for (const id in source) {
18769+
if (!(id in globals)) {
18770+
globals[id] = source[id];
18771+
}
18772+
}
1876518773
}
1876618774
});
1876718775

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ namespace ts {
885885
function convertCompilerOptionsFromJsonWorker(jsonOptions: any,
886886
basePath: string, errors: Diagnostic[], configFileName?: string): CompilerOptions {
887887

888-
const options: CompilerOptions = getBaseFileName(configFileName) === "jsconfig.json" ? { allowJs: true } : {};
888+
const options: CompilerOptions = getBaseFileName(configFileName) === "jsconfig.json" ? { allowJs: true, maxNodeModuleJsDepth: 2 } : {};
889889
convertOptionsFromJson(optionDeclarations, jsonOptions, basePath, options, Diagnostics.Unknown_compiler_option_0, errors);
890890
return options;
891891
}

src/compiler/declarationEmitter.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,8 +1132,10 @@ namespace ts {
11321132
// it if it's not a well known symbol. In that case, the text of the name will be exactly
11331133
// what we want, namely the name expression enclosed in brackets.
11341134
writeTextOfNode(currentText, node.name);
1135-
// If optional property emit ?
1136-
if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature || node.kind === SyntaxKind.Parameter) && hasQuestionToken(node)) {
1135+
// If optional property emit ? but in the case of parameterProperty declaration with "?" indicating optional parameter for the constructor
1136+
// we don't want to emit property declaration with "?"
1137+
if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature ||
1138+
(node.kind === SyntaxKind.Parameter && !isParameterPropertyDeclaration(node))) && hasQuestionToken(node)) {
11371139
write("?");
11381140
}
11391141
if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && node.parent.kind === SyntaxKind.TypeLiteral) {

src/compiler/parser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,6 +2339,7 @@ namespace ts {
23392339
token() === SyntaxKind.LessThanToken ||
23402340
token() === SyntaxKind.QuestionToken ||
23412341
token() === SyntaxKind.ColonToken ||
2342+
token() === SyntaxKind.CommaToken ||
23422343
canParseSemicolon();
23432344
}
23442345
return false;

src/compiler/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,7 @@ namespace ts {
11011101
// - This calls resolveModuleNames, and then calls findSourceFile for each resolved module.
11021102
// As all these operations happen - and are nested - within the createProgram call, they close over the below variables.
11031103
// The current resolution depth is tracked by incrementing/decrementing as the depth first search progresses.
1104-
const maxNodeModulesJsDepth = typeof options.maxNodeModuleJsDepth === "number" ? options.maxNodeModuleJsDepth : 2;
1104+
const maxNodeModulesJsDepth = typeof options.maxNodeModuleJsDepth === "number" ? options.maxNodeModuleJsDepth : 0;
11051105
let currentNodeModulesDepth = 0;
11061106

11071107
// If a module has some of its imports skipped due to being at the depth limit under node_modules, then track

src/harness/unittests/convertCompilerOptionsFromJson.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ namespace ts {
403403
{
404404
compilerOptions: <CompilerOptions>{
405405
allowJs: true,
406+
maxNodeModuleJsDepth: 2,
406407
module: ModuleKind.CommonJS,
407408
target: ScriptTarget.ES5,
408409
noImplicitAny: false,
@@ -429,6 +430,7 @@ namespace ts {
429430
{
430431
compilerOptions: <CompilerOptions>{
431432
allowJs: false,
433+
maxNodeModuleJsDepth: 2,
432434
module: ModuleKind.CommonJS,
433435
target: ScriptTarget.ES5,
434436
noImplicitAny: false,
@@ -450,7 +452,8 @@ namespace ts {
450452
{
451453
compilerOptions:
452454
{
453-
allowJs: true
455+
allowJs: true,
456+
maxNodeModuleJsDepth: 2
454457
},
455458
errors: [{
456459
file: undefined,
@@ -469,7 +472,8 @@ namespace ts {
469472
{
470473
compilerOptions:
471474
{
472-
allowJs: true
475+
allowJs: true,
476+
maxNodeModuleJsDepth: 2
473477
},
474478
errors: <Diagnostic[]>[]
475479
}

src/harness/unittests/tsconfigParsing.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ namespace ts {
186186
const content = `{
187187
"compilerOptions": {
188188
"allowJs": true
189+
// Some comments
189190
"outDir": "bin"
190191
}
191192
"files": ["file1.ts"]

src/services/services.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,14 @@ namespace ts {
280280
let pos = this.pos;
281281
const useJSDocScanner = this.kind >= SyntaxKind.FirstJSDocTagNode && this.kind <= SyntaxKind.LastJSDocTagNode;
282282
const processNode = (node: Node) => {
283-
if (pos < node.pos) {
283+
const isJSDocTagNode = isJSDocTag(node);
284+
if (!isJSDocTagNode && pos < node.pos) {
284285
pos = this.addSyntheticNodes(children, pos, node.pos, useJSDocScanner);
285286
}
286287
children.push(node);
287-
pos = node.end;
288+
if (!isJSDocTagNode) {
289+
pos = node.end;
290+
}
288291
};
289292
const processNodes = (nodes: NodeArray<Node>) => {
290293
if (pos < nodes.pos) {
@@ -299,10 +302,6 @@ namespace ts {
299302
processNode(jsDocComment);
300303
}
301304
}
302-
// For syntactic classifications, all trivia are classcified together, including jsdoc comments.
303-
// For that to work, the jsdoc comments should still be the leading trivia of the first child.
304-
// Restoring the scanner position ensures that.
305-
pos = this.pos;
306305
forEachChild(this, processNode, processNodes);
307306
if (pos < this.end) {
308307
this.addSyntheticNodes(children, pos, this.end);

src/services/utilities.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,8 @@ namespace ts {
930930
const options: TranspileOptions = {
931931
fileName: "config.js",
932932
compilerOptions: {
933-
target: ScriptTarget.ES6
933+
target: ScriptTarget.ES6,
934+
removeComments: true
934935
},
935936
reportDiagnostics: true
936937
};

tests/baselines/reference/declFileConstructors.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ export declare class ConstructorWithPrivateParameterProperty {
247247
constructor(x: string);
248248
}
249249
export declare class ConstructorWithOptionalParameterProperty {
250-
x?: string;
250+
x: string;
251251
constructor(x?: string);
252252
}
253253
export declare class ConstructorWithParameterInitializer {
@@ -281,7 +281,7 @@ declare class GlobalConstructorWithPrivateParameterProperty {
281281
constructor(x: string);
282282
}
283283
declare class GlobalConstructorWithOptionalParameterProperty {
284-
x?: string;
284+
x: string;
285285
constructor(x?: string);
286286
}
287287
declare class GlobalConstructorWithParameterInitializer {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
tests/cases/compiler/errorForConflictingExportEqualsValue.ts(2,1): error TS2309: An export assignment cannot be used in a module with other exported elements.
2+
3+
4+
==== tests/cases/compiler/errorForConflictingExportEqualsValue.ts (1 errors) ====
5+
export var x;
6+
export = {};
7+
~~~~~~~~~~~~
8+
!!! error TS2309: An export assignment cannot be used in a module with other exported elements.
9+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [errorForConflictingExportEqualsValue.ts]
2+
export var x;
3+
export = {};
4+
5+
6+
//// [errorForConflictingExportEqualsValue.js]
7+
"use strict";
8+
module.exports = {};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/index.ts(4,5): error TS2339: Property 'y' does not exist on type 'typeof "shortid"'.
2+
3+
4+
==== /index.ts (1 errors) ====
5+
/// <reference path="/typings/index.d.ts" />
6+
import * as foo from "shortid";
7+
foo.x // found in index.d.ts
8+
foo.y // ignored from shortid/index.js
9+
~
10+
!!! error TS2339: Property 'y' does not exist on type 'typeof "shortid"'.
11+
12+
13+
==== /node_modules/shortid/node_modules/z/index.js (0 errors) ====
14+
// z will not be found because maxNodeModulesJsDepth: 0
15+
module.exports = { z: 'no' };
16+
17+
==== /node_modules/shortid/index.js (0 errors) ====
18+
var z = require('z');
19+
var y = { y: 'foo' };
20+
module.exports = y;
21+
22+
==== /typings/index.d.ts (0 errors) ====
23+
declare module "shortid" {
24+
export var x: number;
25+
}
26+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[
2+
"======== Resolving module 'shortid' from '/index.ts'. ========",
3+
"Explicitly specified module resolution kind: 'NodeJs'.",
4+
"Loading module 'shortid' from 'node_modules' folder.",
5+
"File '/node_modules/shortid.ts' does not exist.",
6+
"File '/node_modules/shortid.tsx' does not exist.",
7+
"File '/node_modules/shortid.d.ts' does not exist.",
8+
"File '/node_modules/shortid.js' does not exist.",
9+
"File '/node_modules/shortid.jsx' does not exist.",
10+
"File '/node_modules/shortid/package.json' does not exist.",
11+
"File '/node_modules/shortid/index.ts' does not exist.",
12+
"File '/node_modules/shortid/index.tsx' does not exist.",
13+
"File '/node_modules/shortid/index.d.ts' does not exist.",
14+
"File '/node_modules/shortid/index.js' exist - use it as a name resolution result.",
15+
"File '/node_modules/@types/shortid.ts' does not exist.",
16+
"File '/node_modules/@types/shortid.tsx' does not exist.",
17+
"File '/node_modules/@types/shortid.d.ts' does not exist.",
18+
"File '/node_modules/@types/shortid.js' does not exist.",
19+
"File '/node_modules/@types/shortid.jsx' does not exist.",
20+
"File '/node_modules/@types/shortid/package.json' does not exist.",
21+
"File '/node_modules/@types/shortid/index.ts' does not exist.",
22+
"File '/node_modules/@types/shortid/index.tsx' does not exist.",
23+
"File '/node_modules/@types/shortid/index.d.ts' does not exist.",
24+
"File '/node_modules/@types/shortid/index.js' does not exist.",
25+
"File '/node_modules/@types/shortid/index.jsx' does not exist.",
26+
"Resolving real path for '/node_modules/shortid/index.js', result '/node_modules/shortid/index.js'",
27+
"======== Module name 'shortid' was successfully resolved to '/node_modules/shortid/index.js'. ========"
28+
]

tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentError.errors.txt

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(4,43): error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ b: string; id: number; }'.
22
Object literal may only specify known properties, and 'name' does not exist in type '{ b: string; id: number; }'.
3-
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(5,16): error TS1131: Property or signature expected.
4-
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(5,22): error TS2403: Subsequent variable declarations must have the same type. Variable 'id' must be of type 'number', but here has type 'any'.
5-
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(5,25): error TS1128: Declaration or statement expected.
63
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(6,79): error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ id: string; name: number; }'.
74
Types of property 'id' are incompatible.
85
Type 'number' is not assignable to type 'string'.
@@ -11,21 +8,15 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPr
118
Type 'number' is not assignable to type 'boolean'.
129

1310

14-
==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts (6 errors) ====
11+
==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts (3 errors) ====
1512
var id: number = 10000;
1613
var name: string = "my name";
1714

1815
var person: { b: string; id: number } = { name, id }; // error
1916
~~~~
2017
!!! error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ b: string; id: number; }'.
2118
!!! error TS2322: Object literal may only specify known properties, and 'name' does not exist in type '{ b: string; id: number; }'.
22-
var person1: { name, id }; // error: can't use short-hand property assignment in type position
23-
~~~~
24-
!!! error TS1131: Property or signature expected.
25-
~~
26-
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'id' must be of type 'number', but here has type 'any'.
27-
~
28-
!!! error TS1128: Declaration or statement expected.
19+
var person1: { name, id }; // ok
2920
function foo(name: string, id: number): { id: string, name: number } { return { name, id }; } // error
3021
~~~~~~~~~~~~
3122
!!! error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ id: string; name: number; }'.

tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentError.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var id: number = 10000;
33
var name: string = "my name";
44

55
var person: { b: string; id: number } = { name, id }; // error
6-
var person1: { name, id }; // error: can't use short-hand property assignment in type position
6+
var person1: { name, id }; // ok
77
function foo(name: string, id: number): { id: string, name: number } { return { name, id }; } // error
88
function bar(obj: { name: string; id: boolean }) { }
99
bar({ name, id }); // error
@@ -14,8 +14,7 @@ bar({ name, id }); // error
1414
var id = 10000;
1515
var name = "my name";
1616
var person = { name: name, id: id }; // error
17-
var person1 = name, id;
18-
; // error: can't use short-hand property assignment in type position
17+
var person1; // ok
1918
function foo(name, id) { return { name: name, id: id }; } // error
2019
function bar(obj) { }
2120
bar({ name: name, id: id }); // error

tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.errors.txt

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPr
33
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(5,79): error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ name: number; id: string; }'.
44
Types of property 'name' are incompatible.
55
Type 'string' is not assignable to type 'number'.
6-
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(7,16): error TS1131: Property or signature expected.
7-
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(7,22): error TS2403: Subsequent variable declarations must have the same type. Variable 'id' must be of type 'number', but here has type 'any'.
8-
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(7,25): error TS1128: Declaration or statement expected.
96
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(8,5): error TS2322: Type '{ name: number; id: string; }' is not assignable to type '{ name: string; id: number; }'.
107
Types of property 'name' are incompatible.
118
Type 'number' is not assignable to type 'string'.
129

1310

14-
==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts (6 errors) ====
11+
==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts (3 errors) ====
1512
var id: number = 10000;
1613
var name: string = "my name";
1714

@@ -25,15 +22,10 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPr
2522
!!! error TS2322: Types of property 'name' are incompatible.
2623
!!! error TS2322: Type 'string' is not assignable to type 'number'.
2724
function foo(name: string, id: number): { name: string, id: number } { return { name, id }; } // error
28-
var person1: { name, id }; // error : Can't use shorthand in the type position
29-
~~~~
30-
!!! error TS1131: Property or signature expected.
31-
~~
32-
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'id' must be of type 'number', but here has type 'any'.
33-
~
34-
!!! error TS1128: Declaration or statement expected.
25+
var person1: { name, id }; // ok
3526
var person2: { name: string, id: number } = bar("hello", 5);
3627
~~~~~~~
3728
!!! error TS2322: Type '{ name: number; id: string; }' is not assignable to type '{ name: string; id: number; }'.
3829
!!! error TS2322: Types of property 'name' are incompatible.
39-
!!! error TS2322: Type 'number' is not assignable to type 'string'.
30+
!!! error TS2322: Type 'number' is not assignable to type 'string'.
31+

0 commit comments

Comments
 (0)