Skip to content

Commit 6165eee

Browse files
add type-level function application
1 parent d03d107 commit 6165eee

File tree

3,743 files changed

+9482
-8058
lines changed

Some content is hidden

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

3,743 files changed

+9482
-8058
lines changed

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ Jakefile.js
1616
.gitattributes
1717
.settings/
1818
.travis.yml
19-
.vscode/
19+
.vscode/
20+
test.config

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ matrix:
1616
branches:
1717
only:
1818
- master
19+
- release-2.5
1920

2021
install:
2122
- npm uninstall typescript --no-save

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "typescript",
33
"author": "Microsoft Corp.",
44
"homepage": "http://typescriptlang.org/",
5-
"version": "2.5.0",
5+
"version": "2.6.0",
66
"license": "Apache-2.0",
77
"description": "TypeScript is a language for application scale JavaScript development",
88
"keywords": [

scripts/buildProtocol.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,23 @@ function endsWith(s: string, suffix: string) {
77
return s.lastIndexOf(suffix, s.length - suffix.length) !== -1;
88
}
99

10+
function isStringEnum(declaration: ts.EnumDeclaration) {
11+
return declaration.members.length && declaration.members.every(m => m.initializer && m.initializer.kind === ts.SyntaxKind.StringLiteral);
12+
}
13+
1014
class DeclarationsWalker {
1115
private visitedTypes: ts.Type[] = [];
1216
private text = "";
1317
private removedTypes: ts.Type[] = [];
14-
18+
1519
private constructor(private typeChecker: ts.TypeChecker, private protocolFile: ts.SourceFile) {
1620
}
1721

1822
static getExtraDeclarations(typeChecker: ts.TypeChecker, protocolFile: ts.SourceFile): string {
1923
let text = "declare namespace ts.server.protocol {\n";
2024
var walker = new DeclarationsWalker(typeChecker, protocolFile);
2125
walker.visitTypeNodes(protocolFile);
22-
text = walker.text
26+
text = walker.text
2327
? `declare namespace ts.server.protocol {\n${walker.text}}`
2428
: "";
2529
if (walker.removedTypes) {
@@ -52,7 +56,7 @@ class DeclarationsWalker {
5256
if (sourceFile === this.protocolFile || path.basename(sourceFile.fileName) === "lib.d.ts") {
5357
return;
5458
}
55-
if (decl.kind === ts.SyntaxKind.EnumDeclaration) {
59+
if (decl.kind === ts.SyntaxKind.EnumDeclaration && !isStringEnum(decl as ts.EnumDeclaration)) {
5660
this.removedTypes.push(type);
5761
return;
5862
}
@@ -91,7 +95,7 @@ class DeclarationsWalker {
9195
for (const type of heritageClauses[0].types) {
9296
this.processTypeOfNode(type);
9397
}
94-
}
98+
}
9599
break;
96100
}
97101
}
@@ -110,7 +114,7 @@ class DeclarationsWalker {
110114
this.processType(type);
111115
}
112116
}
113-
}
117+
}
114118
}
115119

116120
function writeProtocolFile(outputFile: string, protocolTs: string, typeScriptServicesDts: string) {

src/compiler/checker.ts

Lines changed: 92 additions & 66 deletions
Large diffs are not rendered by default.

src/compiler/core.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace ts {
55
// WARNING: The script `configureNightly.ts` uses a regexp to parse out these values.
66
// If changing the text in this section, be sure to test `configureNightly` too.
7-
export const versionMajorMinor = "2.5";
7+
export const versionMajorMinor = "2.6";
88
/** The version of the TypeScript compiler release */
99
export const version = `${versionMajorMinor}.0`;
1010
}
@@ -1543,16 +1543,20 @@ namespace ts {
15431543
}
15441544

15451545
export function normalizePath(path: string): string {
1546+
return normalizePathAndParts(path).path;
1547+
}
1548+
1549+
export function normalizePathAndParts(path: string): { path: string, parts: string[] } {
15461550
path = normalizeSlashes(path);
15471551
const rootLength = getRootLength(path);
15481552
const root = path.substr(0, rootLength);
1549-
const normalized = getNormalizedParts(path, rootLength);
1550-
if (normalized.length) {
1551-
const joinedParts = root + normalized.join(directorySeparator);
1552-
return pathEndsWithDirectorySeparator(path) ? joinedParts + directorySeparator : joinedParts;
1553+
const parts = getNormalizedParts(path, rootLength);
1554+
if (parts.length) {
1555+
const joinedParts = root + parts.join(directorySeparator);
1556+
return { path: pathEndsWithDirectorySeparator(path) ? joinedParts + directorySeparator : joinedParts, parts };
15531557
}
15541558
else {
1555-
return root;
1559+
return { path: root, parts };
15561560
}
15571561
}
15581562

src/compiler/declarationEmitter.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,6 @@ namespace ts {
349349
errorNameNode = declaration.name;
350350
const format = TypeFormatFlags.UseTypeOfFunction |
351351
TypeFormatFlags.WriteClassExpressionAsTypeLiteral |
352-
TypeFormatFlags.UseTypeAliasValue |
353352
(shouldUseResolverType ? TypeFormatFlags.AddUndefined : 0);
354353
resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, format, writer);
355354
errorNameNode = undefined;
@@ -368,7 +367,7 @@ namespace ts {
368367
resolver.writeReturnTypeOfSignatureDeclaration(
369368
signature,
370369
enclosingDeclaration,
371-
TypeFormatFlags.UseTypeOfFunction | TypeFormatFlags.UseTypeAliasValue | TypeFormatFlags.WriteClassExpressionAsTypeLiteral,
370+
TypeFormatFlags.UseTypeOfFunction | TypeFormatFlags.WriteClassExpressionAsTypeLiteral,
372371
writer);
373372
errorNameNode = undefined;
374373
}
@@ -633,7 +632,7 @@ namespace ts {
633632
resolver.writeTypeOfExpression(
634633
expr,
635634
enclosingDeclaration,
636-
TypeFormatFlags.UseTypeOfFunction | TypeFormatFlags.UseTypeAliasValue | TypeFormatFlags.WriteClassExpressionAsTypeLiteral,
635+
TypeFormatFlags.UseTypeOfFunction | TypeFormatFlags.WriteClassExpressionAsTypeLiteral,
637636
writer);
638637
write(";");
639638
writeLine();

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,6 +1912,10 @@
19121912
"category": "Error",
19131913
"code": 2560
19141914
},
1915+
"Base class expressions cannot reference class type parameters.": {
1916+
"category": "Error",
1917+
"code": 2561
1918+
},
19151919
"JSX element attributes type '{0}' may not be a union type.": {
19161920
"category": "Error",
19171921
"code": 2600

src/compiler/emitter.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,8 @@ namespace ts {
753753
return emitPropertyAccessExpression(<PropertyAccessExpression>node);
754754
case SyntaxKind.ElementAccessExpression:
755755
return emitElementAccessExpression(<ElementAccessExpression>node);
756+
case SyntaxKind.TypeCall:
757+
return emitTypeCall(<TypeCallTypeNode>node);
756758
case SyntaxKind.CallExpression:
757759
return emitCallExpression(<CallExpression>node);
758760
case SyntaxKind.NewExpression:
@@ -1240,6 +1242,12 @@ namespace ts {
12401242
write("]");
12411243
}
12421244

1245+
function emitTypeCall(node: TypeCallTypeNode) {
1246+
emit(node.type);
1247+
emitTypeArguments(node, node.typeArguments);
1248+
emitList(node, node.arguments, ListFormat.CallExpressionArguments);
1249+
}
1250+
12431251
function emitCallExpression(node: CallExpression) {
12441252
emitExpression(node.expression);
12451253
emitTypeArguments(node, node.typeArguments);

src/compiler/factory.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,22 @@ namespace ts {
888888
: node;
889889
}
890890

891+
export function createTypeCall(type: TypeNode, typeArguments: ReadonlyArray<TypeNode> | undefined, argumentsArray: ReadonlyArray<TypeNode>) {
892+
const node = <TypeCallTypeNode>createSynthesizedNode(SyntaxKind.TypeCall);
893+
node.type = parenthesizeElementTypeMember(type);
894+
node.typeArguments = asNodeArray(typeArguments);
895+
node.arguments = parenthesizeElementTypeMembers(createNodeArray(argumentsArray));
896+
return node;
897+
}
898+
899+
export function updateTypeCall(node: TypeCallTypeNode, type: TypeNode, typeArguments: ReadonlyArray<TypeNode> | undefined, argumentsArray: ReadonlyArray<TypeNode>) {
900+
return node.type !== type
901+
|| node.typeArguments !== typeArguments
902+
|| node.arguments !== argumentsArray
903+
? updateNode(createTypeCall(type, typeArguments, argumentsArray), node)
904+
: node;
905+
}
906+
891907
export function createCall(expression: Expression, typeArguments: ReadonlyArray<TypeNode> | undefined, argumentsArray: ReadonlyArray<Expression>) {
892908
const node = <CallExpression>createSynthesizedNode(SyntaxKind.CallExpression);
893909
node.expression = parenthesizeForAccess(expression);

src/compiler/moduleNameResolver.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ namespace ts {
201201
let resolvedTypeReferenceDirective: ResolvedTypeReferenceDirective | undefined;
202202
if (resolved) {
203203
if (!options.preserveSymlinks) {
204-
resolved = realpath(resolved, host, traceEnabled);
204+
resolved = realPath(resolved, host, traceEnabled);
205205
}
206206

207207
if (traceEnabled) {
@@ -741,20 +741,21 @@ namespace ts {
741741

742742
let resolvedValue = resolved.value;
743743
if (!compilerOptions.preserveSymlinks) {
744-
resolvedValue = resolvedValue && { ...resolved.value, path: realpath(resolved.value.path, host, traceEnabled), extension: resolved.value.extension };
744+
resolvedValue = resolvedValue && { ...resolved.value, path: realPath(resolved.value.path, host, traceEnabled), extension: resolved.value.extension };
745745
}
746746
// For node_modules lookups, get the real path so that multiple accesses to an `npm link`-ed module do not create duplicate files.
747747
return { value: resolvedValue && { resolved: resolvedValue, isExternalLibraryImport: true } };
748748
}
749749
else {
750-
const candidate = normalizePath(combinePaths(containingDirectory, moduleName));
750+
const { path: candidate, parts } = normalizePathAndParts(combinePaths(containingDirectory, moduleName));
751751
const resolved = nodeLoadModuleByRelativeName(extensions, candidate, failedLookupLocations, /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true);
752-
return resolved && toSearchResult({ resolved, isExternalLibraryImport: false });
752+
// Treat explicit "node_modules" import as an external library import.
753+
return resolved && toSearchResult({ resolved, isExternalLibraryImport: contains(parts, "node_modules") });
753754
}
754755
}
755756
}
756757

757-
function realpath(path: string, host: ModuleResolutionHost, traceEnabled: boolean): string {
758+
function realPath(path: string, host: ModuleResolutionHost, traceEnabled: boolean): string {
758759
if (!host.realpath) {
759760
return path;
760761
}

src/compiler/parser.ts

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ namespace ts {
170170
case SyntaxKind.ElementAccessExpression:
171171
return visitNode(cbNode, (<ElementAccessExpression>node).expression) ||
172172
visitNode(cbNode, (<ElementAccessExpression>node).argumentExpression);
173+
case SyntaxKind.TypeCall:
174+
return visitNode(cbNode, (<TypeCallTypeNode>node).type) ||
175+
visitNodes(cbNode, cbNodes, (<TypeCallTypeNode>node).typeArguments) ||
176+
visitNodes(cbNode, cbNodes, (<TypeCallTypeNode>node).arguments);
173177
case SyntaxKind.CallExpression:
174178
case SyntaxKind.NewExpression:
175179
return visitNode(cbNode, (<CallExpression>node).expression) ||
@@ -2738,8 +2742,8 @@ namespace ts {
27382742
return token() === SyntaxKind.CloseParenToken || isStartOfParameter() || isStartOfType();
27392743
}
27402744

2741-
function parseJSDocPostfixTypeOrHigher(): TypeNode {
2742-
const type = parseNonArrayType();
2745+
function parseJSDocPostfixTypeOrHigher(typeNode?: TypeNode): TypeNode {
2746+
const type = typeNode || parseNonArrayType();
27432747
const kind = getKind(token());
27442748
if (!kind) return type;
27452749
nextToken();
@@ -2761,8 +2765,8 @@ namespace ts {
27612765
}
27622766
}
27632767

2764-
function parseArrayTypeOrHigher(): TypeNode {
2765-
let type = parseJSDocPostfixTypeOrHigher();
2768+
function parseArrayTypeOrHigher(typeNode?: TypeNode): TypeNode {
2769+
let type = parseJSDocPostfixTypeOrHigher(typeNode);
27662770
while (!scanner.hasPrecedingLineBreak() && parseOptional(SyntaxKind.OpenBracketToken)) {
27672771
if (isStartOfType()) {
27682772
const node = <IndexedAccessTypeNode>createNode(SyntaxKind.IndexedAccessType, type.pos);
@@ -2794,7 +2798,7 @@ namespace ts {
27942798
case SyntaxKind.KeyOfKeyword:
27952799
return parseTypeOperator(SyntaxKind.KeyOfKeyword);
27962800
}
2797-
return parseArrayTypeOrHigher();
2801+
return parseTypeCallRest();
27982802
}
27992803

28002804
function parseUnionOrIntersectionType(kind: SyntaxKind.UnionType | SyntaxKind.IntersectionType, parseConstituentType: () => TypeNode, operator: SyntaxKind.BarToken | SyntaxKind.AmpersandToken): TypeNode {
@@ -4240,6 +4244,46 @@ namespace ts {
42404244
}
42414245
}
42424246

4247+
// type equivalent of parseCallExpressionRest
4248+
function parseTypeCallRest(type?: TypeNode): TypeNode {
4249+
while (true) {
4250+
type = parseArrayTypeOrHigher(type);
4251+
if (token() === SyntaxKind.LessThanToken) {
4252+
// See if this is the start of a generic invocation. If so, consume it and
4253+
// keep checking for postfix expressions. Otherwise, it's just a '<' that's
4254+
// part of an arithmetic expression. Break out so we consume it higher in the
4255+
// stack.
4256+
const typeArguments = tryParse(parseTypeArgumentsInExpression);
4257+
if (!typeArguments) {
4258+
return type;
4259+
}
4260+
4261+
const callExpr = <TypeCallTypeNode>createNode(SyntaxKind.TypeCall, type.pos);
4262+
callExpr.type = type;
4263+
callExpr.typeArguments = typeArguments;
4264+
callExpr.arguments = parseTypeArgumentList();
4265+
type = finishNode(callExpr);
4266+
continue;
4267+
}
4268+
else if (token() === SyntaxKind.OpenParenToken) {
4269+
const callExpr = <TypeCallTypeNode>createNode(SyntaxKind.TypeCall, type.pos);
4270+
callExpr.type = type;
4271+
callExpr.arguments = parseTypeArgumentList();
4272+
type = finishNode(callExpr);
4273+
continue;
4274+
}
4275+
4276+
return type;
4277+
}
4278+
}
4279+
4280+
function parseTypeArgumentList() {
4281+
parseExpected(SyntaxKind.OpenParenToken);
4282+
const result = parseDelimitedList(ParsingContext.TypeArguments, parseType);
4283+
parseExpected(SyntaxKind.CloseParenToken);
4284+
return result;
4285+
}
4286+
42434287
function parseCallExpressionRest(expression: LeftHandSideExpression): LeftHandSideExpression {
42444288
while (true) {
42454289
expression = parseMemberExpressionRest(expression);

src/compiler/transformers/es2015.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ namespace ts {
840840
outer.end = skipTrivia(currentText, node.pos);
841841
setEmitFlags(outer, EmitFlags.NoComments);
842842

843-
return createParen(
843+
const result = createParen(
844844
createCall(
845845
outer,
846846
/*typeArguments*/ undefined,
@@ -849,6 +849,8 @@ namespace ts {
849849
: []
850850
)
851851
);
852+
addSyntheticLeadingComment(result, SyntaxKind.MultiLineCommentTrivia, "* @class ");
853+
return result;
852854
}
853855

854856
/**

0 commit comments

Comments
 (0)