Skip to content

Commit af119e9

Browse files
authored
Merge pull request #12608 from Microsoft/mergeMaster1201
Merge master1201
2 parents 46050f4 + 8294e9f commit af119e9

Some content is hidden

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

60 files changed

+1831
-162
lines changed

src/compiler/binder.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,6 @@ namespace ts {
518518
hasExplicitReturn = false;
519519
bindChildren(node);
520520
// Reset all reachability check related flags on node (for incremental scenarios)
521-
// Reset all emit helper flags on node (for incremental scenarios)
522521
node.flags &= ~NodeFlags.ReachabilityAndEmitFlags;
523522
if (!(currentFlow.flags & FlowFlags.Unreachable) && containerFlags & ContainerFlags.IsFunctionLike && nodeIsPresent((<FunctionLikeDeclaration>node).body)) {
524523
node.flags |= NodeFlags.HasImplicitReturn;
@@ -1950,9 +1949,6 @@ namespace ts {
19501949
return bindParameter(<ParameterDeclaration>node);
19511950
case SyntaxKind.VariableDeclaration:
19521951
case SyntaxKind.BindingElement:
1953-
if ((node as BindingElement).dotDotDotToken && node.parent.kind === SyntaxKind.ObjectBindingPattern) {
1954-
emitFlags |= NodeFlags.HasRestAttribute;
1955-
}
19561952
return bindVariableDeclarationOrBindingElement(<VariableDeclaration | BindingElement>node);
19571953
case SyntaxKind.PropertyDeclaration:
19581954
case SyntaxKind.PropertySignature:
@@ -1980,7 +1976,6 @@ namespace ts {
19801976
}
19811977
root = root.parent;
19821978
}
1983-
emitFlags |= hasRest ? NodeFlags.HasRestAttribute : NodeFlags.HasSpreadAttribute;
19841979
return;
19851980

19861981
case SyntaxKind.CallSignature:
@@ -2236,15 +2231,6 @@ namespace ts {
22362231
}
22372232

22382233
function bindClassLikeDeclaration(node: ClassLikeDeclaration) {
2239-
if (!isDeclarationFile(file) && !isInAmbientContext(node)) {
2240-
if (getClassExtendsHeritageClauseElement(node) !== undefined) {
2241-
emitFlags |= NodeFlags.HasClassExtends;
2242-
}
2243-
if (nodeIsDecorated(node)) {
2244-
emitFlags |= NodeFlags.HasDecorators;
2245-
}
2246-
}
2247-
22482234
if (node.kind === SyntaxKind.ClassDeclaration) {
22492235
bindBlockScopedDeclaration(node, SymbolFlags.Class, SymbolFlags.ClassExcludes);
22502236
}
@@ -2314,12 +2300,6 @@ namespace ts {
23142300
}
23152301

23162302
function bindParameter(node: ParameterDeclaration) {
2317-
if (!isDeclarationFile(file) &&
2318-
!isInAmbientContext(node) &&
2319-
nodeIsDecorated(node)) {
2320-
emitFlags |= (NodeFlags.HasDecorators | NodeFlags.HasParamDecorators);
2321-
}
2322-
23232303
if (inStrictMode) {
23242304
// It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a
23252305
// strict mode FunctionLikeDeclaration or FunctionExpression(13.1)
@@ -2377,9 +2357,6 @@ namespace ts {
23772357
if (isAsyncFunctionLike(node)) {
23782358
emitFlags |= NodeFlags.HasAsyncFunctions;
23792359
}
2380-
if (nodeIsDecorated(node)) {
2381-
emitFlags |= NodeFlags.HasDecorators;
2382-
}
23832360
}
23842361

23852362
if (currentFlow && isObjectLiteralOrClassExpressionMethod(node)) {

src/compiler/checker.ts

Lines changed: 120 additions & 68 deletions
Large diffs are not rendered by default.

src/compiler/declarationEmitter.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,6 +1625,12 @@ namespace ts {
16251625
Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
16261626
Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1;
16271627

1628+
case SyntaxKind.IndexSignature:
1629+
// Interfaces cannot have parameter types that cannot be named
1630+
return symbolAccessibilityResult.errorModuleName ?
1631+
Diagnostics.Parameter_0_of_index_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
1632+
Diagnostics.Parameter_0_of_index_signature_from_exported_interface_has_or_is_using_private_name_1;
1633+
16281634
case SyntaxKind.MethodDeclaration:
16291635
case SyntaxKind.MethodSignature:
16301636
if (hasModifier(node.parent, ModifierFlags.Static)) {

src/compiler/diagnosticMessages.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,10 @@
10271027
"category": "Error",
10281028
"code": 2342
10291029
},
1030+
"This syntax requires an imported helper named '{1}', but module '{0}' has no exported member '{1}'.": {
1031+
"category": "Error",
1032+
"code": 2343
1033+
},
10301034
"Type '{0}' does not satisfy the constraint '{1}'.": {
10311035
"category": "Error",
10321036
"code": 2344
@@ -1067,6 +1071,10 @@
10671071
"category": "Error",
10681072
"code": 2353
10691073
},
1074+
"This syntax requires an imported helper but module '{0}' cannot be found.": {
1075+
"category": "Error",
1076+
"code": 2354
1077+
},
10701078
"A function whose declared type is neither 'void' nor 'any' must return a value.": {
10711079
"category": "Error",
10721080
"code": 2355
@@ -2292,6 +2300,14 @@
22922300
"category": "Message",
22932301
"code": 4090
22942302
},
2303+
"Parameter '{0}' of index signature from exported interface has or is using name '{1}' from private module '{2}'.": {
2304+
"category": "Error",
2305+
"code": 4091
2306+
},
2307+
"Parameter '{0}' of index signature from exported interface has or is using private name '{1}'.": {
2308+
"category": "Error",
2309+
"code": 4092
2310+
},
22952311

22962312
"The current host does not support the '{0}' option.": {
22972313
"category": "Error",

src/compiler/transformers/destructuring.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ namespace ts {
459459
var t = {};
460460
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
461461
t[p] = s[p];
462-
if (typeof Object.getOwnPropertySymbols === "function")
462+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
463463
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
464464
t[p[i]] = s[p[i]];
465465
return t;

src/compiler/types.ts

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -418,26 +418,20 @@ namespace ts {
418418
HasImplicitReturn = 1 << 7, // If function implicitly returns on one of codepaths (initialized by binding)
419419
HasExplicitReturn = 1 << 8, // If function has explicit reachable return on one of codepaths (initialized by binding)
420420
GlobalAugmentation = 1 << 9, // Set if module declaration is an augmentation for the global scope
421-
HasClassExtends = 1 << 10, // If the file has a non-ambient class with an extends clause in ES5 or lower (initialized by binding)
422-
HasDecorators = 1 << 11, // If the file has decorators (initialized by binding)
423-
HasParamDecorators = 1 << 12, // If the file has parameter decorators (initialized by binding)
424-
HasAsyncFunctions = 1 << 13, // If the file has async functions (initialized by binding)
425-
HasSpreadAttribute = 1 << 14, // If the file as JSX spread attributes (initialized by binding)
426-
HasRestAttribute = 1 << 15, // If the file has object destructure elements
427-
DisallowInContext = 1 << 16, // If node was parsed in a context where 'in-expressions' are not allowed
428-
YieldContext = 1 << 17, // If node was parsed in the 'yield' context created when parsing a generator
429-
DecoratorContext = 1 << 18, // If node was parsed as part of a decorator
430-
AwaitContext = 1 << 19, // If node was parsed in the 'await' context created when parsing an async function
431-
ThisNodeHasError = 1 << 20, // If the parser encountered an error when parsing the code that created this node
432-
JavaScriptFile = 1 << 21, // If node was parsed in a JavaScript
433-
ThisNodeOrAnySubNodesHasError = 1 << 22, // If this node or any of its children had an error
434-
HasAggregatedChildData = 1 << 23, // If we've computed data from children and cached it in this node
421+
HasAsyncFunctions = 1 << 10, // If the file has async functions (initialized by binding)
422+
DisallowInContext = 1 << 11, // If node was parsed in a context where 'in-expressions' are not allowed
423+
YieldContext = 1 << 12, // If node was parsed in the 'yield' context created when parsing a generator
424+
DecoratorContext = 1 << 13, // If node was parsed as part of a decorator
425+
AwaitContext = 1 << 14, // If node was parsed in the 'await' context created when parsing an async function
426+
ThisNodeHasError = 1 << 15, // If the parser encountered an error when parsing the code that created this node
427+
JavaScriptFile = 1 << 16, // If node was parsed in a JavaScript
428+
ThisNodeOrAnySubNodesHasError = 1 << 17, // If this node or any of its children had an error
429+
HasAggregatedChildData = 1 << 18, // If we've computed data from children and cached it in this node
435430

436431
BlockScoped = Let | Const,
437432

438433
ReachabilityCheckFlags = HasImplicitReturn | HasExplicitReturn,
439-
EmitHelperFlags = HasClassExtends | HasDecorators | HasParamDecorators | HasAsyncFunctions | HasSpreadAttribute | HasRestAttribute,
440-
ReachabilityAndEmitFlags = ReachabilityCheckFlags | EmitHelperFlags,
434+
ReachabilityAndEmitFlags = ReachabilityCheckFlags | HasAsyncFunctions,
441435

442436
// Parsing context flags
443437
ContextFlags = DisallowInContext | YieldContext | DecoratorContext | AwaitContext | JavaScriptFile,
@@ -3698,6 +3692,25 @@ namespace ts {
36983692
readonly priority?: number; // Helpers with a higher priority are emitted earlier than other helpers on the node.
36993693
}
37003694

3695+
/**
3696+
* Used by the checker, this enum keeps track of external emit helpers that should be type
3697+
* checked.
3698+
*/
3699+
/* @internal */
3700+
export const enum ExternalEmitHelpers {
3701+
Extends = 1 << 0, // __extends (used by the ES2015 class transformation)
3702+
Assign = 1 << 1, // __assign (used by Jsx and ESNext object spread transformations)
3703+
Rest = 1 << 2, // __rest (used by ESNext object rest transformation)
3704+
Decorate = 1 << 3, // __decorate (used by TypeScript decorators transformation)
3705+
Metadata = 1 << 4, // __metadata (used by TypeScript decorators transformation)
3706+
Param = 1 << 5, // __param (used by TypeScript decorators transformation)
3707+
Awaiter = 1 << 6, // __awaiter (used by ES2017 async functions transformation)
3708+
Generator = 1 << 7, // __generator (used by ES2015 generator transformation)
3709+
3710+
FirstEmitHelper = Extends,
3711+
LastEmitHelper = Generator
3712+
}
3713+
37013714
/* @internal */
37023715
export const enum EmitContext {
37033716
SourceFile, // Emitting a SourceFile

src/compiler/utilities.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,10 @@ namespace ts {
423423
return false;
424424
}
425425

426+
export function isEffectiveExternalModule(node: SourceFile, compilerOptions: CompilerOptions) {
427+
return isExternalModule(node) || compilerOptions.isolatedModules;
428+
}
429+
426430
export function isBlockScope(node: Node, parentNode: Node) {
427431
switch (node.kind) {
428432
case SyntaxKind.SourceFile:
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
tests/cases/compiler/declarationEmitIndexTypeNotFound.ts(3,6): error TS1023: An index signature parameter type must be 'string' or 'number'.
2+
tests/cases/compiler/declarationEmitIndexTypeNotFound.ts(3,13): error TS2304: Cannot find name 'TypeNotFound'.
3+
tests/cases/compiler/declarationEmitIndexTypeNotFound.ts(3,13): error TS4092: Parameter 'index' of index signature from exported interface has or is using private name 'TypeNotFound'.
4+
5+
6+
==== tests/cases/compiler/declarationEmitIndexTypeNotFound.ts (3 errors) ====
7+
8+
export interface Test {
9+
[index: TypeNotFound]: any;
10+
~~~~~
11+
!!! error TS1023: An index signature parameter type must be 'string' or 'number'.
12+
~~~~~~~~~~~~
13+
!!! error TS2304: Cannot find name 'TypeNotFound'.
14+
~~~~~~~~~~~~
15+
!!! error TS4092: Parameter 'index' of index signature from exported interface has or is using private name 'TypeNotFound'.
16+
}
17+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//// [declarationEmitIndexTypeNotFound.ts]
2+
3+
export interface Test {
4+
[index: TypeNotFound]: any;
5+
}
6+
7+
8+
//// [declarationEmitIndexTypeNotFound.js]
9+
"use strict";

tests/baselines/reference/importHelpersNoHelpers.errors.txt

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,38 @@
1-
error TS2305: Module 'tslib' has no exported member '__assign'.
2-
error TS2305: Module 'tslib' has no exported member '__decorate'.
3-
error TS2305: Module 'tslib' has no exported member '__extends'.
4-
error TS2305: Module 'tslib' has no exported member '__metadata'.
5-
error TS2305: Module 'tslib' has no exported member '__param'.
6-
error TS2305: Module 'tslib' has no exported member '__rest'.
1+
tests/cases/compiler/external.ts(2,16): error TS2343: This syntax requires an imported helper named '__extends', but module 'tslib' has no exported member '__extends'.
2+
tests/cases/compiler/external.ts(6,1): error TS2343: This syntax requires an imported helper named '__decorate', but module 'tslib' has no exported member '__decorate'.
3+
tests/cases/compiler/external.ts(6,1): error TS2343: This syntax requires an imported helper named '__metadata', but module 'tslib' has no exported member '__metadata'.
4+
tests/cases/compiler/external.ts(8,12): error TS2343: This syntax requires an imported helper named '__param', but module 'tslib' has no exported member '__param'.
5+
tests/cases/compiler/external.ts(13,13): error TS2343: This syntax requires an imported helper named '__assign', but module 'tslib' has no exported member '__assign'.
6+
tests/cases/compiler/external.ts(14,12): error TS2343: This syntax requires an imported helper named '__rest', but module 'tslib' has no exported member '__rest'.
77

88

9-
!!! error TS2305: Module 'tslib' has no exported member '__assign'.
10-
!!! error TS2305: Module 'tslib' has no exported member '__decorate'.
11-
!!! error TS2305: Module 'tslib' has no exported member '__extends'.
12-
!!! error TS2305: Module 'tslib' has no exported member '__metadata'.
13-
!!! error TS2305: Module 'tslib' has no exported member '__param'.
14-
!!! error TS2305: Module 'tslib' has no exported member '__rest'.
15-
==== tests/cases/compiler/external.ts (0 errors) ====
9+
==== tests/cases/compiler/external.ts (6 errors) ====
1610
export class A { }
1711
export class B extends A { }
12+
~~~~~~~~~
13+
!!! error TS2343: This syntax requires an imported helper named '__extends', but module 'tslib' has no exported member '__extends'.
1814

1915
declare var dec: any;
2016

2117
@dec
18+
~~~~
19+
!!! error TS2343: This syntax requires an imported helper named '__decorate', but module 'tslib' has no exported member '__decorate'.
20+
~~~~
21+
!!! error TS2343: This syntax requires an imported helper named '__metadata', but module 'tslib' has no exported member '__metadata'.
2222
class C {
2323
method(@dec x: number) {
24+
~~~~
25+
!!! error TS2343: This syntax requires an imported helper named '__param', but module 'tslib' has no exported member '__param'.
2426
}
2527
}
2628

2729
const o = { a: 1 };
2830
const y = { ...o };
31+
~~~~
32+
!!! error TS2343: This syntax requires an imported helper named '__assign', but module 'tslib' has no exported member '__assign'.
2933
const { ...x } = y;
34+
~
35+
!!! error TS2343: This syntax requires an imported helper named '__rest', but module 'tslib' has no exported member '__rest'.
3036

3137
==== tests/cases/compiler/script.ts (0 errors) ====
3238
class A { }

tests/baselines/reference/importHelpersNoModule.errors.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
error TS2307: Cannot find module 'tslib'.
1+
tests/cases/compiler/external.ts(2,16): error TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.
22

33

4-
!!! error TS2307: Cannot find module 'tslib'.
5-
==== tests/cases/compiler/external.ts (0 errors) ====
4+
==== tests/cases/compiler/external.ts (1 errors) ====
65
export class A { }
76
export class B extends A { }
7+
~~~~~~~~~
8+
!!! error TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.
89

910
declare var dec: any;
1011

tests/baselines/reference/isomorphicMappedTypeInference.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,21 @@ function f6(s: string) {
103103
});
104104
let v = unboxify(b);
105105
let x: string | number | boolean = v[s];
106+
}
107+
108+
declare function validate<T>(obj: { [P in keyof T]?: T[P] }): T;
109+
declare function clone<T>(obj: { readonly [P in keyof T]: T[P] }): T;
110+
declare function validateAndClone<T>(obj: { readonly [P in keyof T]?: T[P] }): T;
111+
112+
type Foo = {
113+
a?: number;
114+
readonly b: string;
115+
}
116+
117+
function f10(foo: Foo) {
118+
let x = validate(foo); // { a: number, readonly b: string }
119+
let y = clone(foo); // { a?: number, b: string }
120+
let z = validateAndClone(foo); // { a: number, b: string }
106121
}
107122

108123
//// [isomorphicMappedTypeInference.js]
@@ -190,6 +205,11 @@ function f6(s) {
190205
var v = unboxify(b);
191206
var x = v[s];
192207
}
208+
function f10(foo) {
209+
var x = validate(foo); // { a: number, readonly b: string }
210+
var y = clone(foo); // { a?: number, b: string }
211+
var z = validateAndClone(foo); // { a: number, b: string }
212+
}
193213

194214

195215
//// [isomorphicMappedTypeInference.d.ts]
@@ -220,3 +240,17 @@ declare function makeDictionary<T>(obj: {
220240
[x: string]: T;
221241
};
222242
declare function f6(s: string): void;
243+
declare function validate<T>(obj: {
244+
[P in keyof T]?: T[P];
245+
}): T;
246+
declare function clone<T>(obj: {
247+
readonly [P in keyof T]: T[P];
248+
}): T;
249+
declare function validateAndClone<T>(obj: {
250+
readonly [P in keyof T]?: T[P];
251+
}): T;
252+
declare type Foo = {
253+
a?: number;
254+
readonly b: string;
255+
};
256+
declare function f10(foo: Foo): void;

0 commit comments

Comments
 (0)