Skip to content

Merge master1201 #12608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Dec 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d775f0f
Improve diagnostic messages for imported helpers
rbuckton Nov 16, 2016
f2e30f6
Allow union and intersection as targets for object spread and rest, a…
mhegazy Nov 29, 2016
5c10764
Fix function name
mhegazy Nov 29, 2016
5c4f145
Change name of the function
mhegazy Nov 29, 2016
216f286
Handel null and undefined in object spread and rest
mhegazy Nov 29, 2016
86b48e3
Handel null and undefined in `__rest`
mhegazy Nov 29, 2016
9ab55c1
change test
mhegazy Nov 29, 2016
e4f0a50
Update test name
mhegazy Nov 29, 2016
17b6645
add missing semicolons
mhegazy Nov 29, 2016
51f5ef6
Update test
mhegazy Nov 29, 2016
fe55edc
Rest in an untyped binding pattern should be any
sandersn Nov 29, 2016
f85ca9c
Test that rest of untyped binding pattern is any
sandersn Nov 29, 2016
2178d55
extract filterNullableTypes
mhegazy Nov 30, 2016
2152683
Simplify logic
mhegazy Nov 30, 2016
505c153
Simplify isValidSpreadType
mhegazy Nov 30, 2016
4c9bdb9
Merge pull request #12552 from Microsoft/spreadRestIntersectionAndUnions
mhegazy Nov 30, 2016
f6f866e
Reset the noEmitForJsFiles option when updating compiler options (#12…
zhengbli Nov 30, 2016
e14412a
Improve handling of modifiers in mapped type inference
ahejlsberg Nov 30, 2016
3870351
Accept new baselines
ahejlsberg Nov 30, 2016
2517187
Add tests
ahejlsberg Nov 30, 2016
99f352f
Rest of untyped binding pattern is string-indexed type
sandersn Nov 30, 2016
074ed9f
Update baselines
sandersn Nov 30, 2016
030da0b
Merge pull request #12589 from Microsoft/mappedTypeModifierInference
ahejlsberg Nov 30, 2016
5c294bf
Merge branch 'master' into improveImportHelpersDiagnostics
rbuckton Nov 30, 2016
7a42000
Merge pull request #12305 from Microsoft/improveImportHelpersDiagnostics
rbuckton Nov 30, 2016
f6ace2d
Rest of untyped binding pattern is back to any
sandersn Nov 30, 2016
8e648f9
Add property access and --noImplicitAny tests
sandersn Nov 30, 2016
adf9b26
Handle parameter type error for index signature in declaration emit
sheetalkamat Dec 1, 2016
09f158d
Merge pull request #12594 from Microsoft/indexTypeNotFound
sheetalkamat Dec 1, 2016
ddf03ba
Rest of untyped binding pattern is back to str index sig
sandersn Dec 1, 2016
7722631
Update baselines
sandersn Dec 1, 2016
fc1f6e3
Merge pull request #12564 from Microsoft/rest-of-untyped-binding-patt…
sandersn Dec 1, 2016
2cec8db
Merge pull request #12575 from zhengbli/port12570
mhegazy Dec 1, 2016
8294e9f
Merge branch 'master' into release-2.1
mhegazy Dec 1, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,6 @@ namespace ts {
hasExplicitReturn = false;
bindChildren(node);
// Reset all reachability check related flags on node (for incremental scenarios)
// Reset all emit helper flags on node (for incremental scenarios)
node.flags &= ~NodeFlags.ReachabilityAndEmitFlags;
if (!(currentFlow.flags & FlowFlags.Unreachable) && containerFlags & ContainerFlags.IsFunctionLike && nodeIsPresent((<FunctionLikeDeclaration>node).body)) {
node.flags |= NodeFlags.HasImplicitReturn;
Expand Down Expand Up @@ -1950,9 +1949,6 @@ namespace ts {
return bindParameter(<ParameterDeclaration>node);
case SyntaxKind.VariableDeclaration:
case SyntaxKind.BindingElement:
if ((node as BindingElement).dotDotDotToken && node.parent.kind === SyntaxKind.ObjectBindingPattern) {
emitFlags |= NodeFlags.HasRestAttribute;
}
return bindVariableDeclarationOrBindingElement(<VariableDeclaration | BindingElement>node);
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.PropertySignature:
Expand Down Expand Up @@ -1980,7 +1976,6 @@ namespace ts {
}
root = root.parent;
}
emitFlags |= hasRest ? NodeFlags.HasRestAttribute : NodeFlags.HasSpreadAttribute;
return;

case SyntaxKind.CallSignature:
Expand Down Expand Up @@ -2236,15 +2231,6 @@ namespace ts {
}

function bindClassLikeDeclaration(node: ClassLikeDeclaration) {
if (!isDeclarationFile(file) && !isInAmbientContext(node)) {
if (getClassExtendsHeritageClauseElement(node) !== undefined) {
emitFlags |= NodeFlags.HasClassExtends;
}
if (nodeIsDecorated(node)) {
emitFlags |= NodeFlags.HasDecorators;
}
}

if (node.kind === SyntaxKind.ClassDeclaration) {
bindBlockScopedDeclaration(node, SymbolFlags.Class, SymbolFlags.ClassExcludes);
}
Expand Down Expand Up @@ -2314,12 +2300,6 @@ namespace ts {
}

function bindParameter(node: ParameterDeclaration) {
if (!isDeclarationFile(file) &&
!isInAmbientContext(node) &&
nodeIsDecorated(node)) {
emitFlags |= (NodeFlags.HasDecorators | NodeFlags.HasParamDecorators);
}

if (inStrictMode) {
// It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a
// strict mode FunctionLikeDeclaration or FunctionExpression(13.1)
Expand Down Expand Up @@ -2377,9 +2357,6 @@ namespace ts {
if (isAsyncFunctionLike(node)) {
emitFlags |= NodeFlags.HasAsyncFunctions;
}
if (nodeIsDecorated(node)) {
emitFlags |= NodeFlags.HasDecorators;
}
}

if (currentFlow && isObjectLiteralOrClassExpressionMethod(node)) {
Expand Down
188 changes: 120 additions & 68 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/compiler/declarationEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,12 @@ namespace ts {
Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1;

case SyntaxKind.IndexSignature:
// Interfaces cannot have parameter types that cannot be named
return symbolAccessibilityResult.errorModuleName ?
Diagnostics.Parameter_0_of_index_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
Diagnostics.Parameter_0_of_index_signature_from_exported_interface_has_or_is_using_private_name_1;

case SyntaxKind.MethodDeclaration:
case SyntaxKind.MethodSignature:
if (hasModifier(node.parent, ModifierFlags.Static)) {
Expand Down
16 changes: 16 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,10 @@
"category": "Error",
"code": 2342
},
"This syntax requires an imported helper named '{1}', but module '{0}' has no exported member '{1}'.": {
"category": "Error",
"code": 2343
},
"Type '{0}' does not satisfy the constraint '{1}'.": {
"category": "Error",
"code": 2344
Expand Down Expand Up @@ -1067,6 +1071,10 @@
"category": "Error",
"code": 2353
},
"This syntax requires an imported helper but module '{0}' cannot be found.": {
"category": "Error",
"code": 2354
},
"A function whose declared type is neither 'void' nor 'any' must return a value.": {
"category": "Error",
"code": 2355
Expand Down Expand Up @@ -2292,6 +2300,14 @@
"category": "Message",
"code": 4090
},
"Parameter '{0}' of index signature from exported interface has or is using name '{1}' from private module '{2}'.": {
"category": "Error",
"code": 4091
},
"Parameter '{0}' of index signature from exported interface has or is using private name '{1}'.": {
"category": "Error",
"code": 4092
},

"The current host does not support the '{0}' option.": {
"category": "Error",
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/destructuring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ namespace ts {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (typeof Object.getOwnPropertySymbols === "function")
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
t[p[i]] = s[p[i]];
return t;
Expand Down
45 changes: 29 additions & 16 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,26 +418,20 @@ namespace ts {
HasImplicitReturn = 1 << 7, // If function implicitly returns on one of codepaths (initialized by binding)
HasExplicitReturn = 1 << 8, // If function has explicit reachable return on one of codepaths (initialized by binding)
GlobalAugmentation = 1 << 9, // Set if module declaration is an augmentation for the global scope
HasClassExtends = 1 << 10, // If the file has a non-ambient class with an extends clause in ES5 or lower (initialized by binding)
HasDecorators = 1 << 11, // If the file has decorators (initialized by binding)
HasParamDecorators = 1 << 12, // If the file has parameter decorators (initialized by binding)
HasAsyncFunctions = 1 << 13, // If the file has async functions (initialized by binding)
HasSpreadAttribute = 1 << 14, // If the file as JSX spread attributes (initialized by binding)
HasRestAttribute = 1 << 15, // If the file has object destructure elements
DisallowInContext = 1 << 16, // If node was parsed in a context where 'in-expressions' are not allowed
YieldContext = 1 << 17, // If node was parsed in the 'yield' context created when parsing a generator
DecoratorContext = 1 << 18, // If node was parsed as part of a decorator
AwaitContext = 1 << 19, // If node was parsed in the 'await' context created when parsing an async function
ThisNodeHasError = 1 << 20, // If the parser encountered an error when parsing the code that created this node
JavaScriptFile = 1 << 21, // If node was parsed in a JavaScript
ThisNodeOrAnySubNodesHasError = 1 << 22, // If this node or any of its children had an error
HasAggregatedChildData = 1 << 23, // If we've computed data from children and cached it in this node
HasAsyncFunctions = 1 << 10, // If the file has async functions (initialized by binding)
DisallowInContext = 1 << 11, // If node was parsed in a context where 'in-expressions' are not allowed
YieldContext = 1 << 12, // If node was parsed in the 'yield' context created when parsing a generator
DecoratorContext = 1 << 13, // If node was parsed as part of a decorator
AwaitContext = 1 << 14, // If node was parsed in the 'await' context created when parsing an async function
ThisNodeHasError = 1 << 15, // If the parser encountered an error when parsing the code that created this node
JavaScriptFile = 1 << 16, // If node was parsed in a JavaScript
ThisNodeOrAnySubNodesHasError = 1 << 17, // If this node or any of its children had an error
HasAggregatedChildData = 1 << 18, // If we've computed data from children and cached it in this node

BlockScoped = Let | Const,

ReachabilityCheckFlags = HasImplicitReturn | HasExplicitReturn,
EmitHelperFlags = HasClassExtends | HasDecorators | HasParamDecorators | HasAsyncFunctions | HasSpreadAttribute | HasRestAttribute,
ReachabilityAndEmitFlags = ReachabilityCheckFlags | EmitHelperFlags,
ReachabilityAndEmitFlags = ReachabilityCheckFlags | HasAsyncFunctions,

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

/**
* Used by the checker, this enum keeps track of external emit helpers that should be type
* checked.
*/
/* @internal */
export const enum ExternalEmitHelpers {
Extends = 1 << 0, // __extends (used by the ES2015 class transformation)
Assign = 1 << 1, // __assign (used by Jsx and ESNext object spread transformations)
Rest = 1 << 2, // __rest (used by ESNext object rest transformation)
Decorate = 1 << 3, // __decorate (used by TypeScript decorators transformation)
Metadata = 1 << 4, // __metadata (used by TypeScript decorators transformation)
Param = 1 << 5, // __param (used by TypeScript decorators transformation)
Awaiter = 1 << 6, // __awaiter (used by ES2017 async functions transformation)
Generator = 1 << 7, // __generator (used by ES2015 generator transformation)

FirstEmitHelper = Extends,
LastEmitHelper = Generator
}

/* @internal */
export const enum EmitContext {
SourceFile, // Emitting a SourceFile
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,10 @@ namespace ts {
return false;
}

export function isEffectiveExternalModule(node: SourceFile, compilerOptions: CompilerOptions) {
return isExternalModule(node) || compilerOptions.isolatedModules;
}

export function isBlockScope(node: Node, parentNode: Node) {
switch (node.kind) {
case SyntaxKind.SourceFile:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
tests/cases/compiler/declarationEmitIndexTypeNotFound.ts(3,6): error TS1023: An index signature parameter type must be 'string' or 'number'.
tests/cases/compiler/declarationEmitIndexTypeNotFound.ts(3,13): error TS2304: Cannot find name 'TypeNotFound'.
tests/cases/compiler/declarationEmitIndexTypeNotFound.ts(3,13): error TS4092: Parameter 'index' of index signature from exported interface has or is using private name 'TypeNotFound'.


==== tests/cases/compiler/declarationEmitIndexTypeNotFound.ts (3 errors) ====

export interface Test {
[index: TypeNotFound]: any;
~~~~~
!!! error TS1023: An index signature parameter type must be 'string' or 'number'.
~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'TypeNotFound'.
~~~~~~~~~~~~
!!! error TS4092: Parameter 'index' of index signature from exported interface has or is using private name 'TypeNotFound'.
}

9 changes: 9 additions & 0 deletions tests/baselines/reference/declarationEmitIndexTypeNotFound.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//// [declarationEmitIndexTypeNotFound.ts]

export interface Test {
[index: TypeNotFound]: any;
}


//// [declarationEmitIndexTypeNotFound.js]
"use strict";
32 changes: 19 additions & 13 deletions tests/baselines/reference/importHelpersNoHelpers.errors.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
error TS2305: Module 'tslib' has no exported member '__assign'.
error TS2305: Module 'tslib' has no exported member '__decorate'.
error TS2305: Module 'tslib' has no exported member '__extends'.
error TS2305: Module 'tslib' has no exported member '__metadata'.
error TS2305: Module 'tslib' has no exported member '__param'.
error TS2305: Module 'tslib' has no exported member '__rest'.
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'.
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'.
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'.
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'.
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'.
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'.


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

declare var dec: any;

@dec
~~~~
!!! error TS2343: This syntax requires an imported helper named '__decorate', but module 'tslib' has no exported member '__decorate'.
~~~~
!!! error TS2343: This syntax requires an imported helper named '__metadata', but module 'tslib' has no exported member '__metadata'.
class C {
method(@dec x: number) {
~~~~
!!! error TS2343: This syntax requires an imported helper named '__param', but module 'tslib' has no exported member '__param'.
}
}

const o = { a: 1 };
const y = { ...o };
~~~~
!!! error TS2343: This syntax requires an imported helper named '__assign', but module 'tslib' has no exported member '__assign'.
const { ...x } = y;
~
!!! error TS2343: This syntax requires an imported helper named '__rest', but module 'tslib' has no exported member '__rest'.

==== tests/cases/compiler/script.ts (0 errors) ====
class A { }
Expand Down
7 changes: 4 additions & 3 deletions tests/baselines/reference/importHelpersNoModule.errors.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
error TS2307: Cannot find module 'tslib'.
tests/cases/compiler/external.ts(2,16): error TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.


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

declare var dec: any;

Expand Down
34 changes: 34 additions & 0 deletions tests/baselines/reference/isomorphicMappedTypeInference.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,21 @@ function f6(s: string) {
});
let v = unboxify(b);
let x: string | number | boolean = v[s];
}

declare function validate<T>(obj: { [P in keyof T]?: T[P] }): T;
declare function clone<T>(obj: { readonly [P in keyof T]: T[P] }): T;
declare function validateAndClone<T>(obj: { readonly [P in keyof T]?: T[P] }): T;

type Foo = {
a?: number;
readonly b: string;
}

function f10(foo: Foo) {
let x = validate(foo); // { a: number, readonly b: string }
let y = clone(foo); // { a?: number, b: string }
let z = validateAndClone(foo); // { a: number, b: string }
}

//// [isomorphicMappedTypeInference.js]
Expand Down Expand Up @@ -190,6 +205,11 @@ function f6(s) {
var v = unboxify(b);
var x = v[s];
}
function f10(foo) {
var x = validate(foo); // { a: number, readonly b: string }
var y = clone(foo); // { a?: number, b: string }
var z = validateAndClone(foo); // { a: number, b: string }
}


//// [isomorphicMappedTypeInference.d.ts]
Expand Down Expand Up @@ -220,3 +240,17 @@ declare function makeDictionary<T>(obj: {
[x: string]: T;
};
declare function f6(s: string): void;
declare function validate<T>(obj: {
[P in keyof T]?: T[P];
}): T;
declare function clone<T>(obj: {
readonly [P in keyof T]: T[P];
}): T;
declare function validateAndClone<T>(obj: {
readonly [P in keyof T]?: T[P];
}): T;
declare type Foo = {
a?: number;
readonly b: string;
};
declare function f10(foo: Foo): void;
Loading