Skip to content

Commit 0c1772b

Browse files
author
Arthur Ozga
committed
Merge branch 'interfaceFixes' of https://github.com/Microsoft/TypeScript into interfaceFixes
2 parents ba80ce6 + 8134d64 commit 0c1772b

File tree

111 files changed

+7428
-813
lines changed

Some content is hidden

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

111 files changed

+7428
-813
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: 275 additions & 154 deletions
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ namespace ts {
272272
"es2017": ScriptTarget.ES2017,
273273
"esnext": ScriptTarget.ESNext,
274274
}),
275-
description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015,
275+
description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_ES2015_ES2016_ES2017_or_ESNEXT,
276276
paramType: Diagnostics.VERSION,
277277
},
278278
{

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: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,10 @@
851851
"category": "Error",
852852
"code": 1317
853853
},
854+
"An abstract accessor cannot have an implementation.": {
855+
"category": "Error",
856+
"code": 1318
857+
},
854858
"Duplicate identifier '{0}'.": {
855859
"category": "Error",
856860
"code": 2300
@@ -1023,6 +1027,10 @@
10231027
"category": "Error",
10241028
"code": 2342
10251029
},
1030+
"This syntax requires an imported helper named '{1}', but module '{0}' has no exported member '{1}'.": {
1031+
"category": "Error",
1032+
"code": 2343
1033+
},
10261034
"Type '{0}' does not satisfy the constraint '{1}'.": {
10271035
"category": "Error",
10281036
"code": 2344
@@ -1063,6 +1071,10 @@
10631071
"category": "Error",
10641072
"code": 2353
10651073
},
1074+
"This syntax requires an imported helper but module '{0}' cannot be found.": {
1075+
"category": "Error",
1076+
"code": 2354
1077+
},
10661078
"A function whose declared type is neither 'void' nor 'any' must return a value.": {
10671079
"category": "Error",
10681080
"code": 2355
@@ -2288,6 +2300,14 @@
22882300
"category": "Message",
22892301
"code": 4090
22902302
},
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+
},
22912311

22922312
"The current host does not support the '{0}' option.": {
22932313
"category": "Error",
@@ -2453,7 +2473,7 @@
24532473
"category": "Message",
24542474
"code": 6012
24552475
},
2456-
"Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES2015'": {
2476+
"Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'": {
24572477
"category": "Message",
24582478
"code": 6015
24592479
},

src/compiler/parser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2558,6 +2558,8 @@ namespace ts {
25582558
case SyntaxKind.OpenBraceToken:
25592559
case SyntaxKind.OpenBracketToken:
25602560
case SyntaxKind.LessThanToken:
2561+
case SyntaxKind.BarToken:
2562+
case SyntaxKind.AmpersandToken:
25612563
case SyntaxKind.NewKeyword:
25622564
case SyntaxKind.StringLiteral:
25632565
case SyntaxKind.NumericLiteral:
@@ -2617,6 +2619,7 @@ namespace ts {
26172619
}
26182620

26192621
function parseUnionOrIntersectionType(kind: SyntaxKind, parseConstituentType: () => TypeNode, operator: SyntaxKind): TypeNode {
2622+
parseOptional(operator);
26202623
let type = parseConstituentType();
26212624
if (token() === operator) {
26222625
const types = createNodeArray<TypeNode>([type], type.pos);

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/transformers/ts.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ namespace ts {
345345

346346
case SyntaxKind.PropertyDeclaration:
347347
// TypeScript property declarations are elided.
348+
return undefined;
348349

349350
case SyntaxKind.Constructor:
350351
return visitConstructor(<ConstructorDeclaration>node);
@@ -1905,7 +1906,7 @@ namespace ts {
19051906
: (<ComputedPropertyName>name).expression;
19061907
}
19071908
else if (isIdentifier(name)) {
1908-
return createLiteral(name.text);
1909+
return createLiteral(unescapeIdentifier(name.text));
19091910
}
19101911
else {
19111912
return getSynthesizedClone(name);

src/compiler/types.ts

Lines changed: 47 additions & 25 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,
@@ -2808,6 +2802,7 @@ namespace ts {
28082802
UnionOrIntersection = Union | Intersection,
28092803
StructuredType = Object | Union | Intersection,
28102804
StructuredOrTypeParameter = StructuredType | TypeParameter | Index,
2805+
TypeVariable = TypeParameter | IndexedAccess,
28112806

28122807
// 'Narrowable' types are types where narrowing actually narrows.
28132808
// This *should* be every type other than null, undefined, void, and never
@@ -2920,7 +2915,9 @@ namespace ts {
29202915
/* @internal */
29212916
resolvedProperties: SymbolTable; // Cache of resolved properties
29222917
/* @internal */
2923-
couldContainTypeParameters: boolean;
2918+
resolvedIndexType: IndexType;
2919+
/* @internal */
2920+
couldContainTypeVariables: boolean;
29242921
}
29252922

29262923
export interface UnionType extends UnionOrIntersectionType { }
@@ -2976,8 +2973,13 @@ namespace ts {
29762973
iteratorElementType?: Type;
29772974
}
29782975

2976+
export interface TypeVariable extends Type {
2977+
/* @internal */
2978+
resolvedIndexType: IndexType;
2979+
}
2980+
29792981
// Type parameters (TypeFlags.TypeParameter)
2980-
export interface TypeParameter extends Type {
2982+
export interface TypeParameter extends TypeVariable {
29812983
constraint: Type; // Constraint
29822984
/* @internal */
29832985
target?: TypeParameter; // Instantiation target
@@ -2986,20 +2988,21 @@ namespace ts {
29862988
/* @internal */
29872989
resolvedApparentType: Type;
29882990
/* @internal */
2989-
resolvedIndexType: IndexType;
2990-
/* @internal */
29912991
isThisType?: boolean;
29922992
}
29932993

2994-
export interface IndexType extends Type {
2995-
type: TypeParameter;
2996-
}
2997-
2998-
export interface IndexedAccessType extends Type {
2994+
// Indexed access types (TypeFlags.IndexedAccess)
2995+
// Possible forms are T[xxx], xxx[T], or xxx[keyof T], where T is a type variable
2996+
export interface IndexedAccessType extends TypeVariable {
29992997
objectType: Type;
30002998
indexType: Type;
30012999
}
30023000

3001+
// keyof T types (TypeFlags.Index)
3002+
export interface IndexType extends Type {
3003+
type: TypeVariable | UnionOrIntersectionType;
3004+
}
3005+
30033006
export const enum SignatureKind {
30043007
Call,
30053008
Construct,
@@ -3705,6 +3708,25 @@ namespace ts {
37053708
readonly priority?: number; // Helpers with a higher priority are emitted earlier than other helpers on the node.
37063709
}
37073710

3711+
/**
3712+
* Used by the checker, this enum keeps track of external emit helpers that should be type
3713+
* checked.
3714+
*/
3715+
/* @internal */
3716+
export const enum ExternalEmitHelpers {
3717+
Extends = 1 << 0, // __extends (used by the ES2015 class transformation)
3718+
Assign = 1 << 1, // __assign (used by Jsx and ESNext object spread transformations)
3719+
Rest = 1 << 2, // __rest (used by ESNext object rest transformation)
3720+
Decorate = 1 << 3, // __decorate (used by TypeScript decorators transformation)
3721+
Metadata = 1 << 4, // __metadata (used by TypeScript decorators transformation)
3722+
Param = 1 << 5, // __param (used by TypeScript decorators transformation)
3723+
Awaiter = 1 << 6, // __awaiter (used by ES2017 async functions transformation)
3724+
Generator = 1 << 7, // __generator (used by ES2015 generator transformation)
3725+
3726+
FirstEmitHelper = Extends,
3727+
LastEmitHelper = Generator
3728+
}
3729+
37083730
/* @internal */
37093731
export const enum EmitContext {
37103732
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:

0 commit comments

Comments
 (0)