Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7a9c11c
Test:destructuring array initialisers refer to previous elements
sandersn Dec 6, 2016
92f2721
Binding initialisers can refer to previous elements
sandersn Dec 6, 2016
72a1e85
Check binding initialisers in parameters as well
sandersn Dec 6, 2016
4efa61c
More tests for binding elements referencing previous elements
sandersn Dec 6, 2016
77b6482
Add baselines for new tests
sandersn Dec 6, 2016
3202d59
Merge remote-tracking branch 'refs/remotes/Microsoft/master'
saschanaz Dec 10, 2016
603ba89
Merge branch 'master' of https://github.com/Microsoft/TypeScript
saschanaz Dec 16, 2016
8ae9c7d
JSDoc functions are now in scope for instantiation
sandersn Dec 16, 2016
5940379
Add serialization of typenode for null/undefined/never as part of met…
sheetalkamat Nov 29, 2016
73a8292
Support union of non identifier serialized type node with null/undefi…
sheetalkamat Nov 29, 2016
1045f3b
detach root files on project close if project language service is dis…
vladima Dec 21, 2016
cddc72a
always give container
saschanaz Dec 21, 2016
54fb29b
format generic type alias
saschanaz Dec 21, 2016
bc59d62
format [P in keyof T]
saschanaz Dec 21, 2016
f4c33aa
indent inside mapped type
saschanaz Dec 21, 2016
c28625f
merge conflict
saschanaz Dec 21, 2016
a4ec7d6
unindent dangling closing token
saschanaz Dec 21, 2016
ba7c1a1
do not insert space after function expressions
saschanaz Dec 21, 2016
2576ea1
fix linter alert
saschanaz Dec 21, 2016
32568b3
Test case when module member is object spread pattern
sheetalkamat Dec 21, 2016
330cced
cache results of module resolution for non-relative module names (#13…
vladima Dec 21, 2016
6281d1d
Merge pull request #12982 from Microsoft/jsdoc-instantiate-signature-…
sandersn Dec 21, 2016
e9da643
Merge pull request #13090 from SaschaNaz/maptype
mhegazy Dec 21, 2016
14cce29
Do not report error on unused removed property from object spread
sheetalkamat Dec 21, 2016
62426de
Nit: Moving type aliases for serialized type nodes as per feedback
sheetalkamat Dec 21, 2016
4cbb50a
Merge pull request #13034 from Microsoft/unionWithNull
sheetalkamat Dec 21, 2016
32c477a
Test case for metadata type of class from a module
sheetalkamat Dec 21, 2016
08e6b1b
Update current scope when visiting namespace elements
sheetalkamat Dec 21, 2016
db1fda5
Improve diagnostic message for negative old style literals
arusakov Dec 20, 2016
23faaff
isMinusPrefixUnaryExpression() -> isPrefixUnaryExpression() after cod…
arusakov Dec 21, 2016
74a9924
Merge pull request #13100 from Microsoft/unusedLocalsInSpread
sheetalkamat Dec 21, 2016
0c2cce5
Merge pull request #13103 from Microsoft/metadataOfClassFromModule
sheetalkamat Dec 21, 2016
445cf0e
Merge pull request #13056 from arusakov/improve_diagnostic_message_ne…
mhegazy Dec 21, 2016
784f29b
merge conflict
saschanaz Dec 22, 2016
e8b3ff0
Merge pull request #12694 from Microsoft/destructuring-initialisers-c…
sandersn Dec 22, 2016
c563e83
Merge pull request #13092 from SaschaNaz/jsxdangling
mhegazy Dec 22, 2016
3d350a2
Merge branch 'master' into release-2.1
mhegazy Dec 22, 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
60 changes: 49 additions & 11 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,11 +636,24 @@ namespace ts {

if (declaration.pos <= usage.pos) {
// declaration is before usage
// still might be illegal if usage is in the initializer of the variable declaration
return declaration.kind !== SyntaxKind.VariableDeclaration ||
!isImmediatelyUsedInInitializerOfBlockScopedVariable(<VariableDeclaration>declaration, usage);
if (declaration.kind === SyntaxKind.BindingElement) {
// still might be illegal if declaration and usage are both binding elements (eg var [a = b, b = b] = [1, 2])
const errorBindingElement = getAncestor(usage, SyntaxKind.BindingElement) as BindingElement;
if (errorBindingElement) {
return getAncestorBindingPattern(errorBindingElement) !== getAncestorBindingPattern(declaration) ||
declaration.pos < errorBindingElement.pos;
}
// or it might be illegal if usage happens before parent variable is declared (eg var [a] = a)
return isBlockScopedNameDeclaredBeforeUse(getAncestor(declaration, SyntaxKind.VariableDeclaration) as Declaration, usage);
}
else if (declaration.kind === SyntaxKind.VariableDeclaration) {
// still might be illegal if usage is in the initializer of the variable declaration (eg var a = a)
return !isImmediatelyUsedInInitializerOfBlockScopedVariable(declaration as VariableDeclaration, usage);
}
return true;
}


// declaration is after usage
// can be legal if usage is deferred (i.e. inside function or in initializer of instance property)
const container = getEnclosingBlockScopeContainer(declaration);
Expand Down Expand Up @@ -697,6 +710,16 @@ namespace ts {
}
return false;
}

function getAncestorBindingPattern(node: Node): BindingPattern {
while (node) {
if (isBindingPattern(node)) {
return node;
}
node = node.parent;
}
return undefined;
}
}

// Resolve a given name for a given meaning at a given location. An error is reported if the name was not found and
Expand Down Expand Up @@ -1063,7 +1086,7 @@ namespace ts {

Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined");

if (!isInAmbientContext(declaration) && !isBlockScopedNameDeclaredBeforeUse(<Declaration>getAncestor(declaration, SyntaxKind.VariableDeclaration), errorLocation)) {
if (!isInAmbientContext(declaration) && !isBlockScopedNameDeclaredBeforeUse(declaration, errorLocation)) {
error(errorLocation, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, declarationNameToString(declaration.name));
}
}
Expand Down Expand Up @@ -6645,7 +6668,7 @@ namespace ts {
// Starting with the parent of the symbol's declaration, check if the mapper maps any of
// the type parameters introduced by enclosing declarations. We just pick the first
// declaration since multiple declarations will all have the same parent anyway.
let node = symbol.declarations[0].parent;
let node: Node = symbol.declarations[0];
while (node) {
switch (node.kind) {
case SyntaxKind.FunctionType:
Expand All @@ -6665,7 +6688,7 @@ namespace ts {
case SyntaxKind.ClassExpression:
case SyntaxKind.InterfaceDeclaration:
case SyntaxKind.TypeAliasDeclaration:
const declaration = <DeclarationWithTypeParameters>node;
const declaration = node as DeclarationWithTypeParameters;
if (declaration.typeParameters) {
for (const d of declaration.typeParameters) {
if (contains(mappedTypes, getDeclaredTypeOfTypeParameter(getSymbolOfNode(d)))) {
Expand All @@ -6680,6 +6703,14 @@ namespace ts {
}
}
break;
case SyntaxKind.JSDocFunctionType:
const func = node as JSDocFunctionType;
for (const p of func.parameters) {
if (contains(mappedTypes, getTypeOfNode(p))) {
return true;
}
}
break;
case SyntaxKind.ModuleDeclaration:
case SyntaxKind.SourceFile:
return false;
Expand Down Expand Up @@ -16891,7 +16922,7 @@ namespace ts {
if (!local.isReferenced && !local.exportSymbol) {
for (const declaration of local.declarations) {
if (!isAmbientModule(declaration)) {
error(declaration.name, Diagnostics._0_is_declared_but_never_used, local.name);
errorUnusedLocal(declaration.name, local.name);
}
}
}
Expand Down Expand Up @@ -17149,7 +17180,8 @@ namespace ts {
// so we need to do a bit of extra work to check if reference is legal
const enclosingContainer = getEnclosingBlockScopeContainer(symbol.valueDeclaration);
if (enclosingContainer === func) {
if (symbol.valueDeclaration.kind === SyntaxKind.Parameter) {
if (symbol.valueDeclaration.kind === SyntaxKind.Parameter ||
symbol.valueDeclaration.kind === SyntaxKind.BindingElement) {
// it is ok to reference parameter in initializer if either
// - parameter is located strictly on the left of current parameter declaration
if (symbol.valueDeclaration.pos < node.pos) {
Expand Down Expand Up @@ -21849,11 +21881,17 @@ namespace ts {
function checkGrammarNumericLiteral(node: NumericLiteral): boolean {
// Grammar checking
if (node.isOctalLiteral) {
let diagnosticMessage: DiagnosticMessage | undefined;
if (languageVersion >= ScriptTarget.ES5) {
return grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0o_0, node.text);
diagnosticMessage = Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0;
}
else if (isChildOfLiteralType(node)) {
diagnosticMessage = Diagnostics.Octal_literal_types_must_use_ES2015_syntax_Use_the_syntax_0;
}
if (isChildOfLiteralType(node)) {
return grammarErrorOnNode(node, Diagnostics.Octal_literal_types_must_use_ES2015_syntax_Use_the_syntax_0o_0, node.text);
if (diagnosticMessage) {
const withMinus = isPrefixUnaryExpression(node.parent) && node.parent.operator === SyntaxKind.MinusToken;
const literal = `${withMinus ? "-" : ""}0o${node.text}`;
return grammarErrorOnNode(withMinus ? node.parent : node, diagnosticMessage, literal);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
"category": "Error",
"code": 1084
},
"Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o{0}'.": {
"Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '{0}'.": {
"category": "Error",
"code": 1085
},
Expand Down Expand Up @@ -2952,7 +2952,7 @@
"Resolution for module '{0}' was found in cache": {
"category": "Message",
"code": 6147
},
},
"Variable '{0}' implicitly has an '{1}' type.": {
"category": "Error",
"code": 7005
Expand Down Expand Up @@ -3243,7 +3243,7 @@
"category": "Message",
"code": 90015
},
"Octal literal types must use ES2015 syntax. Use the syntax '0o{0}'.": {
"Octal literal types must use ES2015 syntax. Use the syntax '{0}'.": {
"category": "Error",
"code": 8017
}
Expand Down
Loading