Commit graph

2132 commits

Author SHA1 Message Date
Sheetal Nandi 52a8560298 Typeguards of form !expr
•	A type guard of the form !expr
o	when true, narrows the type of x by expr when false, or
o	when false, narrows the type of x by expr when true.
2014-11-06 13:04:43 -08:00
Sheetal Nandi c9a03dc659 Typeguards of form expr1 || expr2
•	A type guard of the form expr1 || expr2
o	when true, narrows the type of x to T1 | T2, where T1 is the type of x narrowed by expr1 when true, and T2 is the type of x narrowed by expr1 when false and then by expr2 when true, or
o	when false, narrows the type of x by expr1 when false and then by expr2 when false.
2014-11-06 13:04:40 -08:00
Sheetal Nandi 486d37ec90 TypeGuard of for expr1 && expr2
•	A type guard of the form expr1 && expr2
o	when true, narrows the type of x by expr1 when true and then by expr2 when true, or
o	when false, narrows the type of x to T1 | T2, where T1 is the type of x narrowed by expr1 when false, and T2 is the type of x narrowed by expr1 when true and then by expr2 when false.
2014-11-06 13:04:37 -08:00
Sheetal Nandi 7ebf5371a5 Test cases for typeguards of form typeof x === s and typeof x !== s
•	A type guard of the form typeof x === s, where s is a string literal with the value ‘string’, ‘number’, or ‘boolean’,
o	when true, narrows the type of x to the given primitive type, or
o	when false, removes the primitive type from the type of x.
•	A type guard of the form typeof x === s, where s is a string literal with any value but ‘string’, ‘number’, or ‘boolean’,
o	when true, removes the primitive types string, number, and boolean from the type of x, or
o	when false, has no effect on the type of x.
•	A type guard of the form typeof x !== s, where s is a string literal,
o	when true, narrows the type of x by typeof x === s when false, or
o	when false, narrows the type of x by typeof x === s when true.
2014-11-06 13:04:34 -08:00
Sheetal Nandi 5961ed7154 Test typeguard of form instance of
•	A type guard of the form x instanceof C, where C is of a subtype of the global type ‘Function’ and C has a property named ‘prototype’
o	when true, narrows the type of x to the type of the ‘prototype’ property in C provided it is a subtype of the type of x, or
o	when false, has no effect on the type of x.
2014-11-06 13:04:30 -08:00
Sheetal Nandi 2fecc132ab Tests for typeguards allowed on variables and parameters only
From spec:
Note that type guards affect types of variables and parameters only and have no effect on members of objects such as properties
2014-11-06 13:04:27 -08:00
Sheetal Nandi 33cdc2f876 Type guards in || operator
•	In the right operand of a || operation, the type of a variable or parameter is narrowed by any type guard in the left operand when false, provided the right operand contains no assignments to the variable or parameter.
2014-11-06 13:04:24 -08:00
Sheetal Nandi 11912e8fde TypeGuards in right operand of && operation
•	In the right operand of a && operation, the type of a variable or parameter is narrowed by any type guard in the left operand when true, provided the right operand contains no assignments to the variable or parameter.
2014-11-06 13:04:21 -08:00
Sheetal Nandi 55952af304 Tests for conditional expression typeguards
•	In the true expression of a conditional expression, the type of a variable or parameter is narrowed by any type guard in the condition when true, provided the expression contains no assignments to the variable or parameter.
•	In the false expression of a conditional expression, the type of a variable or parameter is narrowed by any type guard in the condition when false, provided the expression contains no assignments to the variable or parameter.
2014-11-06 13:04:18 -08:00
Sheetal Nandi 4b3d603f24 Test cases for typeguards are scoped at function /module block 2014-11-06 13:04:14 -08:00
Sheetal Nandi 2088a89223 Test cases to make sure typeguard is defeated in case of function calls
From spec:
Also note that it is possible to defeat a type guard by calling a function that changes the type of the guarded variable.
2014-11-06 13:04:11 -08:00
Sheetal Nandi e79bec5cbf TypeGuards narrow types in if statement works per spec:
The type of a variable or parameter is narrowed in the following situations:
•	In the true branch statement of an ‘if’ statement, the type of a variable or parameter is narrowed by any type guard in the ‘if’ condition when true, provided the if statement contains no assignments to the variable or parameter.
•	In the false branch statement of an ‘if’ statement, the type of a variable or parameter is narrowed by any type guard in the ‘if’ condition when false, provided the if statement contains no assignments to the variable or parameter.
2014-11-06 13:04:08 -08:00
Jason Freeman 2145b2f445 Merge pull request #1071 from Microsoft/computedPropertyName
Change name of Declaration node to be Identifier | ComputedPropertyName
2014-11-06 12:05:48 -08:00
Jason Freeman 5164fbc3bd Merge branch 'master' into computedPropertyName 2014-11-06 11:52:19 -08:00
Jason Freeman 279166be50 Address feedback 2014-11-06 11:51:49 -08:00
vladima c3a88d3482 code cleanup: replace nulls with undefined 2014-11-06 11:10:27 -08:00
vladima ace99ad051 code cleanup, removed unused files 2014-11-06 10:57:19 -08:00
vladima bbc2da79bb return last scanned token if possible 2014-11-06 00:37:58 -08:00
CyrusNajmabadi 147550e2d3 Merge pull request #1065 from Microsoft/shorthandProperties
Add support for parsing shorthand property assignments.
2014-11-05 22:53:43 -08:00
Vladimir Matveev 154977ce95 add child delta for all nodes 2014-11-05 19:35:53 -08:00
Daniel Rosenwasser 652b7f8909 Corrected comment. 2014-11-05 18:34:53 -08:00
Daniel Rosenwasser bcddb101aa Proper type arg inference with apppropriate overload res tests. 2014-11-05 18:20:40 -08:00
Jason Freeman bc70e4a29d Make certain types of FunctionLike require block bodies 2014-11-05 18:04:19 -08:00
Jason Freeman 6c85dbe140 Refactor Declaration.name into Identifier | ComputedPropertyName 2014-11-05 17:47:30 -08:00
Vladimir Matveev edbb99d959 merge with master 2014-11-05 17:34:42 -08:00
Vladimir Matveev 13054710c7 track effective parent indentation for list items 2014-11-05 17:07:47 -08:00
Vladimir Matveev 680b59481b fix indentation for nested items 2014-11-05 15:35:18 -08:00
Vladimir Matveev 9a30fa882b do not indent tokens with errors 2014-11-05 15:29:51 -08:00
Vladimir Matveev f28c1a3498 fix indentations in functions 2014-11-05 15:23:11 -08:00
Daniel Rosenwasser fea1165186 Merge branch 'master' into taggedTemplates 2014-11-05 14:06:19 -08:00
Daniel Rosenwasser 356622c8e9 Merge pull request #1067 from Microsoft/deduplicateTypeNotAssignableMessage
Removed duplicate diagnostic message.
2014-11-05 12:48:57 -08:00
Daniel Rosenwasser e12e31b144 Removed duplicate diagnostic. 2014-11-05 12:26:03 -08:00
Cyrus Najmabadi bea124b217 Simplify code. 2014-11-05 04:08:20 -08:00
Cyrus Najmabadi 1a1c9ace8a Add support for parsing computed property names. 2014-11-05 03:49:25 -08:00
Cyrus Najmabadi cb97682d83 Add the IPropertyNameSyntax.
This will help us introduce the ComputedPropertyName concept in the future.

Conflicts:
	src/services/syntax/syntaxNodes.concrete.generated.ts
2014-11-05 00:54:53 -08:00
Cyrus Najmabadi ae87b08e33 Add support for parsing shorthand property assignments. 2014-11-04 23:04:07 -08:00
CyrusNajmabadi fff8ef8b84 Merge pull request #1063 from Microsoft/nodeCleanup
Node cleanup
2014-11-04 23:03:13 -08:00
Cyrus Najmabadi 5952036e2c Remove unnecessary brand. 2014-11-04 22:43:11 -08:00
Cyrus Najmabadi 3753058874 Add an IAccessorSyntax interface. 2014-11-04 22:43:01 -08:00
Cyrus Najmabadi ba2bdc4124 Add missing brands to the syntax interfaces. 2014-11-04 22:42:43 -08:00
Cyrus Najmabadi a9a2fe501a Specialize computeData for arrays. 2014-11-04 22:41:13 -08:00
Cyrus Najmabadi 4cefe353f3 remove file. 2014-11-04 22:40:59 -08:00
Cyrus Najmabadi 35644b3d47 Move from an array of function pointers to actual methods.
Conflicts:
	src/services/syntax/syntaxGenerator.ts
2014-11-04 22:40:36 -08:00
Anders Hejlsberg d8080a0b46 Merge pull request #1035 from Microsoft/improvedTypeInference
Improved type inference (fixes #1011)
2014-11-04 17:09:31 -08:00
Sheetal Nandi a5cea935af Tests for contextual index signature of union type
Let S be the set of types in U that has a string index signature. If S is not empty, U has a string index signature of a union type of the types of the string index signatures from each type in S.
Let S be the set of types in U that has a numeric index signature. If S is not empty, U has a numeric index signature of a union type of the types of the numeric index signatures from each type in S.
2014-11-04 15:33:32 -08:00
Daniel Rosenwasser 1508350cb8 Merge branch 'master' into taggedTemplates
Conflicts:
	tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.errors.txt
2014-11-04 15:24:21 -08:00
Daniel Rosenwasser 56027663bf Initial work on overload resolution with tagged templates.
Currently type argument inference breaks hard when the first parameter of a tag has a generic type.
2014-11-04 15:05:05 -08:00
Sheetal Nandi c4e632746e Fix the logic in getting the contextual signature of union type as per spec
Fixes #1054
2014-11-04 14:49:15 -08:00
Sheetal Nandi c5b4051f3a Test cases for contextual typing of union type members 2014-11-04 13:33:43 -08:00
Vladimir Matveev 2b701963ee Merge pull request #1049 from Microsoft/const_enums
Convert majority of enums in compiler to const enums
2014-11-04 12:28:40 -08:00