Skip to content

Commit 519095f

Browse files
committed
Merge branch 'master' into syntaxKindLiterals
2 parents 49695ed + 3212e25 commit 519095f

File tree

120 files changed

+25279
-252
lines changed

Some content is hidden

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

120 files changed

+25279
-252
lines changed

Gulpfile.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -725,16 +725,16 @@ declare module "convert-source-map" {
725725
}
726726

727727
gulp.task("browserify", "Runs browserify on run.js to produce a file suitable for running tests in the browser", [servicesFile], (done) => {
728-
const testProject = tsc.createProject("src/harness/tsconfig.json", getCompilerSettings({ outFile: "built/local/bundle.js" }, /*useBuiltCompiler*/ true));
728+
const testProject = tsc.createProject("src/harness/tsconfig.json", getCompilerSettings({ outFile: "../../built/local/bundle.js" }, /*useBuiltCompiler*/ true));
729729
return testProject.src()
730730
.pipe(newer("built/local/bundle.js"))
731731
.pipe(sourcemaps.init())
732-
.pipe(testProject)
732+
.pipe(testProject())
733733
.pipe(through2.obj((file, enc, next) => {
734734
const originalMap = file.sourceMap;
735735
const prebundledContent = file.contents.toString();
736736
// Make paths absolute to help sorcery deal with all the terrible paths being thrown around
737-
originalMap.sources = originalMap.sources.map(s => path.resolve("src", s));
737+
originalMap.sources = originalMap.sources.map(s => path.resolve(s));
738738
// intoStream (below) makes browserify think the input file is named this, so this is what it puts in the sourcemap
739739
originalMap.file = "built/local/_stream_0.js";
740740

scripts/processDiagnosticMessages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, nameMap:
8686
'/// <reference path="types.ts" />\r\n' +
8787
'/* @internal */\r\n' +
8888
'namespace ts {\r\n' +
89-
' export var Diagnostics = {\r\n';
89+
' export const Diagnostics = {\r\n';
9090
var names = Utilities.getObjectKeys(messageTable);
9191
for (var i = 0; i < names.length; i++) {
9292
var name = names[i];

src/compiler/binder.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2432,8 +2432,7 @@ namespace ts {
24322432
}
24332433

24342434
// If the parameter's name is 'this', then it is TypeScript syntax.
2435-
if (subtreeFlags & TransformFlags.ContainsDecorators
2436-
|| (name && isIdentifier(name) && name.originalKeywordKind === SyntaxKind.ThisKeyword)) {
2435+
if (subtreeFlags & TransformFlags.ContainsDecorators || isThisIdentifier(name)) {
24372436
transformFlags |= TransformFlags.AssertTypeScript;
24382437
}
24392438

src/compiler/checker.ts

Lines changed: 55 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,7 +2165,7 @@ namespace ts {
21652165
? "any"
21662166
: (<IntrinsicType>type).intrinsicName);
21672167
}
2168-
else if (type.flags & TypeFlags.ThisType) {
2168+
else if (type.flags & TypeFlags.TypeParameter && (type as TypeParameter).isThisType) {
21692169
if (inObjectTypeLiteral) {
21702170
writer.reportInaccessibleThisError();
21712171
}
@@ -2183,9 +2183,14 @@ namespace ts {
21832183
// The specified symbol flags need to be reinterpreted as type flags
21842184
buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, nextFlags);
21852185
}
2186-
else if (!(flags & TypeFormatFlags.InTypeAlias) && type.flags & (TypeFlags.Anonymous | TypeFlags.UnionOrIntersection) && type.aliasSymbol &&
2186+
else if (!(flags & TypeFormatFlags.InTypeAlias) && ((type.flags & TypeFlags.Anonymous && !(<AnonymousType>type).target) || type.flags & TypeFlags.UnionOrIntersection) && type.aliasSymbol &&
21872187
isSymbolAccessible(type.aliasSymbol, enclosingDeclaration, SymbolFlags.Type, /*shouldComputeAliasesToMakeVisible*/ false).accessibility === SymbolAccessibility.Accessible) {
2188-
// Only write out inferred type with its corresponding type-alias if type-alias is visible
2188+
// We emit inferred type as type-alias at the current localtion if all the following is true
2189+
// the input type is has alias symbol that is accessible
2190+
// the input type is a union, intersection or anonymous type that is fully instantiated (if not we want to keep dive into)
2191+
// e.g.: export type Bar<X, Y> = () => [X, Y];
2192+
// export type Foo<Y> = Bar<any, Y>;
2193+
// export const y = (x: Foo<string>) => 1 // we want to emit as ...x: () => [any, string])
21892194
const typeArguments = type.aliasTypeArguments;
21902195
writeSymbolTypeReference(type.aliasSymbol, typeArguments, 0, typeArguments ? typeArguments.length : 0, nextFlags);
21912196
}
@@ -3179,7 +3184,7 @@ namespace ts {
31793184
result.pattern = pattern;
31803185
}
31813186
if (hasComputedProperties) {
3182-
result.flags |= TypeFlags.ObjectLiteralPatternWithComputedProperties;
3187+
result.isObjectLiteralPatternWithComputedProperties = true;
31833188
}
31843189
return result;
31853190
}
@@ -3766,7 +3771,8 @@ namespace ts {
37663771
(<GenericType>type).instantiations[getTypeListId(type.typeParameters)] = <GenericType>type;
37673772
(<GenericType>type).target = <GenericType>type;
37683773
(<GenericType>type).typeArguments = type.typeParameters;
3769-
type.thisType = <TypeParameter>createType(TypeFlags.TypeParameter | TypeFlags.ThisType);
3774+
type.thisType = <TypeParameter>createType(TypeFlags.TypeParameter);
3775+
type.thisType.isThisType = true;
37703776
type.thisType.symbol = symbol;
37713777
type.thisType.constraint = type;
37723778
}
@@ -4968,7 +4974,7 @@ namespace ts {
49684974

49694975
function hasConstraintReferenceTo(type: Type, target: TypeParameter): boolean {
49704976
let checked: Type[];
4971-
while (type && !(type.flags & TypeFlags.ThisType) && type.flags & TypeFlags.TypeParameter && !contains(checked, type)) {
4977+
while (type && type.flags & TypeFlags.TypeParameter && !((type as TypeParameter).isThisType) && !contains(checked, type)) {
49724978
if (type === target) {
49734979
return true;
49744980
}
@@ -5331,7 +5337,8 @@ namespace ts {
53315337
type.instantiations[getTypeListId(type.typeParameters)] = <GenericType>type;
53325338
type.target = <GenericType>type;
53335339
type.typeArguments = type.typeParameters;
5334-
type.thisType = <TypeParameter>createType(TypeFlags.TypeParameter | TypeFlags.ThisType);
5340+
type.thisType = <TypeParameter>createType(TypeFlags.TypeParameter);
5341+
type.thisType.isThisType = true;
53355342
type.thisType.constraint = type;
53365343
type.declaredProperties = properties;
53375344
type.declaredCallSignatures = emptyArray;
@@ -5444,7 +5451,26 @@ namespace ts {
54445451
return false;
54455452
}
54465453

5454+
function isSetOfLiteralsFromSameEnum(types: TypeSet): boolean {
5455+
const first = types[0];
5456+
if (first.flags & TypeFlags.EnumLiteral) {
5457+
const firstEnum = getParentOfSymbol(first.symbol);
5458+
for (let i = 1; i < types.length; i++) {
5459+
const other = types[i];
5460+
if (!(other.flags & TypeFlags.EnumLiteral) || (firstEnum !== getParentOfSymbol(other.symbol))) {
5461+
return false;
5462+
}
5463+
}
5464+
return true;
5465+
}
5466+
5467+
return false;
5468+
}
5469+
54475470
function removeSubtypes(types: TypeSet) {
5471+
if (types.length === 0 || isSetOfLiteralsFromSameEnum(types)) {
5472+
return;
5473+
}
54485474
let i = types.length;
54495475
while (i > 0) {
54505476
i--;
@@ -6647,7 +6673,8 @@ namespace ts {
66476673
}
66486674

66496675
function hasExcessProperties(source: FreshObjectLiteralType, target: Type, reportErrors: boolean): boolean {
6650-
if (!(target.flags & TypeFlags.ObjectLiteralPatternWithComputedProperties) && maybeTypeOfKind(target, TypeFlags.ObjectType)) {
6676+
if (maybeTypeOfKind(target, TypeFlags.ObjectType) &&
6677+
(!(target.flags & TypeFlags.ObjectType) || !(target as ObjectType).isObjectLiteralPatternWithComputedProperties)) {
66516678
for (const prop of getPropertiesOfObjectType(source)) {
66526679
if (!isKnownProperty(target, prop.name)) {
66536680
if (reportErrors) {
@@ -9351,7 +9378,7 @@ namespace ts {
93519378
captureLexicalThis(node, container);
93529379
}
93539380
if (isFunctionLike(container) &&
9354-
(!isInParameterInitializerBeforeContainingFunction(node) || getFunctionLikeThisParameter(container))) {
9381+
(!isInParameterInitializerBeforeContainingFunction(node) || getThisParameter(container))) {
93559382
// Note: a parameter initializer should refer to class-this unless function-this is explicitly annotated.
93569383

93579384
// If this is a function in a JS file, it might be a class method. Check if it's the RHS
@@ -9753,7 +9780,7 @@ namespace ts {
97539780
// corresponding set accessor has a type annotation, return statements in the function are contextually typed
97549781
if (functionDecl.type ||
97559782
functionDecl.kind === SyntaxKind.Constructor ||
9756-
functionDecl.kind === SyntaxKind.GetAccessor && getSetAccessorTypeAnnotationNode(<AccessorDeclaration>getDeclarationOfKind(functionDecl.symbol, SyntaxKind.SetAccessor))) {
9783+
functionDecl.kind === SyntaxKind.GetAccessor && getSetAccessorTypeAnnotationNode(<SetAccessorDeclaration>getDeclarationOfKind(functionDecl.symbol, SyntaxKind.SetAccessor))) {
97579784
return getReturnTypeOfSignature(getSignatureFromDeclaration(functionDecl));
97589785
}
97599786

@@ -10307,7 +10334,8 @@ namespace ts {
1030710334
patternWithComputedProperties = true;
1030810335
}
1030910336
}
10310-
else if (contextualTypeHasPattern && !(contextualType.flags & TypeFlags.ObjectLiteralPatternWithComputedProperties)) {
10337+
else if (contextualTypeHasPattern &&
10338+
!(contextualType.flags & TypeFlags.ObjectType && (contextualType as ObjectType).isObjectLiteralPatternWithComputedProperties)) {
1031110339
// If object literal is contextually typed by the implied type of a binding pattern, and if the
1031210340
// binding pattern specifies a default value for the property, make the property optional.
1031310341
const impliedProp = getPropertyOfType(contextualType, member.name);
@@ -10372,7 +10400,10 @@ namespace ts {
1037210400
const numberIndexInfo = hasComputedNumberProperty ? getObjectLiteralIndexInfo(node, propertiesArray, IndexKind.Number) : undefined;
1037310401
const result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo);
1037410402
const freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : TypeFlags.FreshLiteral;
10375-
result.flags |= TypeFlags.ObjectLiteral | TypeFlags.ContainsObjectLiteral | freshObjectLiteralFlag | (typeFlags & TypeFlags.PropagatingFlags) | (patternWithComputedProperties ? TypeFlags.ObjectLiteralPatternWithComputedProperties : 0);
10403+
result.flags |= TypeFlags.ObjectLiteral | TypeFlags.ContainsObjectLiteral | freshObjectLiteralFlag | (typeFlags & TypeFlags.PropagatingFlags);
10404+
if (patternWithComputedProperties) {
10405+
result.isObjectLiteralPatternWithComputedProperties = true;
10406+
}
1037610407
if (inDestructuringPattern) {
1037710408
result.pattern = node;
1037810409
}
@@ -10942,7 +10973,7 @@ namespace ts {
1094210973
return true;
1094310974
}
1094410975
// An instance property must be accessed through an instance of the enclosing class
10945-
if (type.flags & TypeFlags.ThisType) {
10976+
if (type.flags & TypeFlags.TypeParameter && (type as TypeParameter).isThisType) {
1094610977
// get the original type -- represented as the type constraint of the 'this' type
1094710978
type = getConstraintOfTypeParameter(<TypeParameter>type);
1094810979
}
@@ -10992,7 +11023,7 @@ namespace ts {
1099211023
const prop = getPropertyOfType(apparentType, right.text);
1099311024
if (!prop) {
1099411025
if (right.text && !checkAndReportErrorForExtendingInterface(node)) {
10995-
reportNonexistentProperty(right, type.flags & TypeFlags.ThisType ? apparentType : type);
11026+
reportNonexistentProperty(right, type.flags & TypeFlags.TypeParameter && (type as TypeParameter).isThisType ? apparentType : type);
1099611027
}
1099711028
return unknownType;
1099811029
}
@@ -12740,7 +12771,10 @@ namespace ts {
1274012771
if (!contextualSignature) {
1274112772
reportErrorsFromWidening(func, type);
1274212773
}
12743-
if (isUnitType(type) && !(contextualSignature && isLiteralContextualType(getReturnTypeOfSignature(contextualSignature)))) {
12774+
if (isUnitType(type) &&
12775+
!(contextualSignature &&
12776+
isLiteralContextualType(
12777+
contextualSignature === getSignatureFromDeclaration(func) ? type : getReturnTypeOfSignature(contextualSignature)))) {
1274412778
type = getWidenedLiteralType(type);
1274512779
}
1274612780

@@ -15531,10 +15565,6 @@ namespace ts {
1553115565
}
1553215566
}
1553315567

15534-
function parameterIsThisKeyword(parameter: ParameterDeclaration) {
15535-
return parameter.name && (<Identifier>parameter.name).originalKeywordKind === SyntaxKind.ThisKeyword;
15536-
}
15537-
1553815568
function parameterNameStartsWithUnderscore(parameter: ParameterDeclaration) {
1553915569
return parameter.name && parameter.name.kind === SyntaxKind.Identifier && (<Identifier>parameter.name).text.charCodeAt(0) === CharacterCodes._;
1554015570
}
@@ -16427,7 +16457,7 @@ namespace ts {
1642716457
}
1642816458

1642916459
function isGetAccessorWithAnnotatedSetAccessor(node: FunctionLikeDeclaration) {
16430-
return !!(node.kind === SyntaxKind.GetAccessor && getSetAccessorTypeAnnotationNode(<AccessorDeclaration>getDeclarationOfKind(node.symbol, SyntaxKind.SetAccessor)));
16460+
return !!(node.kind === SyntaxKind.GetAccessor && getSetAccessorTypeAnnotationNode(<SetAccessorDeclaration>getDeclarationOfKind(node.symbol, SyntaxKind.SetAccessor)));
1643116461
}
1643216462

1643316463
function isUnwrappedReturnTypeVoidOrAny(func: FunctionLikeDeclaration, returnType: Type): boolean {
@@ -18432,6 +18462,9 @@ namespace ts {
1843218462
(<ImportDeclaration>node.parent).moduleSpecifier === node)) {
1843318463
return resolveExternalModuleName(node, <LiteralExpression>node);
1843418464
}
18465+
if (isInJavaScriptFile(node) && isRequireCall(node.parent, /*checkArgumentIsStringLiteral*/ false)) {
18466+
return resolveExternalModuleName(node, <LiteralExpression>node);
18467+
}
1843518468
// Fall through
1843618469

1843718470
case SyntaxKind.NumericLiteral:
@@ -20117,18 +20150,8 @@ namespace ts {
2011720150
}
2011820151

2011920152
function getAccessorThisParameter(accessor: AccessorDeclaration): ParameterDeclaration {
20120-
if (accessor.parameters.length === (accessor.kind === SyntaxKind.GetAccessor ? 1 : 2) &&
20121-
accessor.parameters[0].name.kind === SyntaxKind.Identifier &&
20122-
(<Identifier>accessor.parameters[0].name).originalKeywordKind === SyntaxKind.ThisKeyword) {
20123-
return accessor.parameters[0];
20124-
}
20125-
}
20126-
20127-
function getFunctionLikeThisParameter(func: FunctionLikeDeclaration) {
20128-
if (func.parameters.length &&
20129-
func.parameters[0].name.kind === SyntaxKind.Identifier &&
20130-
(<Identifier>func.parameters[0].name).originalKeywordKind === SyntaxKind.ThisKeyword) {
20131-
return func.parameters[0];
20153+
if (accessor.parameters.length === (accessor.kind === SyntaxKind.GetAccessor ? 1 : 2)) {
20154+
return getThisParameter(accessor);
2013220155
}
2013320156
}
2013420157

src/compiler/core.ts

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ namespace ts {
212212
* true for all elements, otherwise returns a new array instance containing the filtered subset.
213213
*/
214214
export function filter<T, U extends T>(array: T[], f: (x: T) => x is U): U[];
215-
export function filter<T>(array: T[], f: (x: T) => boolean): T[]
215+
export function filter<T>(array: T[], f: (x: T) => boolean): T[];
216216
export function filter<T>(array: T[], f: (x: T) => boolean): T[] {
217217
if (array) {
218218
const len = array.length;
@@ -1867,10 +1867,10 @@ namespace ts {
18671867
declare var process: any;
18681868
declare var require: any;
18691869

1870-
let currentAssertionLevel: AssertionLevel;
1870+
export let currentAssertionLevel = AssertionLevel.None;
18711871

18721872
export function shouldAssert(level: AssertionLevel): boolean {
1873-
return getCurrentAssertionLevel() >= level;
1873+
return currentAssertionLevel >= level;
18741874
}
18751875

18761876
export function assert(expression: boolean, message?: string, verboseDebugInfo?: () => string): void {
@@ -1887,35 +1887,6 @@ namespace ts {
18871887
export function fail(message?: string): void {
18881888
Debug.assert(/*expression*/ false, message);
18891889
}
1890-
1891-
function getCurrentAssertionLevel() {
1892-
if (currentAssertionLevel !== undefined) {
1893-
return currentAssertionLevel;
1894-
}
1895-
1896-
if (sys === undefined) {
1897-
return AssertionLevel.None;
1898-
}
1899-
1900-
const developmentMode = /^development$/i.test(getEnvironmentVariable("NODE_ENV"));
1901-
currentAssertionLevel = developmentMode
1902-
? AssertionLevel.Normal
1903-
: AssertionLevel.None;
1904-
1905-
return currentAssertionLevel;
1906-
}
1907-
}
1908-
1909-
export function getEnvironmentVariable(name: string, host?: CompilerHost) {
1910-
if (host && host.getEnvironmentVariable) {
1911-
return host.getEnvironmentVariable(name);
1912-
}
1913-
1914-
if (sys && sys.getEnvironmentVariable) {
1915-
return sys.getEnvironmentVariable(name);
1916-
}
1917-
1918-
return "";
19191890
}
19201891

19211892
/** Remove an item from an array, moving everything to its right one space left. */

0 commit comments

Comments
 (0)