Skip to content

Commit

Permalink
add type-level function application
Browse files Browse the repository at this point in the history
  • Loading branch information
KiaraGrouwstra committed Aug 22, 2017
1 parent d03d107 commit 6165eee
Show file tree
Hide file tree
Showing 3,743 changed files with 9,482 additions and 8,058 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ Jakefile.js
.gitattributes
.settings/
.travis.yml
.vscode/
.vscode/
test.config
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ matrix:
branches:
only:
- master
- release-2.5

install:
- npm uninstall typescript --no-save
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "typescript",
"author": "Microsoft Corp.",
"homepage": "http://typescriptlang.org/",
"version": "2.5.0",
"version": "2.6.0",
"license": "Apache-2.0",
"description": "TypeScript is a language for application scale JavaScript development",
"keywords": [
Expand Down
14 changes: 9 additions & 5 deletions scripts/buildProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@ function endsWith(s: string, suffix: string) {
return s.lastIndexOf(suffix, s.length - suffix.length) !== -1;
}

function isStringEnum(declaration: ts.EnumDeclaration) {
return declaration.members.length && declaration.members.every(m => m.initializer && m.initializer.kind === ts.SyntaxKind.StringLiteral);
}

class DeclarationsWalker {
private visitedTypes: ts.Type[] = [];
private text = "";
private removedTypes: ts.Type[] = [];

private constructor(private typeChecker: ts.TypeChecker, private protocolFile: ts.SourceFile) {
}

static getExtraDeclarations(typeChecker: ts.TypeChecker, protocolFile: ts.SourceFile): string {
let text = "declare namespace ts.server.protocol {\n";
var walker = new DeclarationsWalker(typeChecker, protocolFile);
walker.visitTypeNodes(protocolFile);
text = walker.text
text = walker.text
? `declare namespace ts.server.protocol {\n${walker.text}}`
: "";
if (walker.removedTypes) {
Expand Down Expand Up @@ -52,7 +56,7 @@ class DeclarationsWalker {
if (sourceFile === this.protocolFile || path.basename(sourceFile.fileName) === "lib.d.ts") {
return;
}
if (decl.kind === ts.SyntaxKind.EnumDeclaration) {
if (decl.kind === ts.SyntaxKind.EnumDeclaration && !isStringEnum(decl as ts.EnumDeclaration)) {
this.removedTypes.push(type);
return;
}
Expand Down Expand Up @@ -91,7 +95,7 @@ class DeclarationsWalker {
for (const type of heritageClauses[0].types) {
this.processTypeOfNode(type);
}
}
}
break;
}
}
Expand All @@ -110,7 +114,7 @@ class DeclarationsWalker {
this.processType(type);
}
}
}
}
}

function writeProtocolFile(outputFile: string, protocolTs: string, typeScriptServicesDts: string) {
Expand Down
158 changes: 92 additions & 66 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace ts {
// WARNING: The script `configureNightly.ts` uses a regexp to parse out these values.
// If changing the text in this section, be sure to test `configureNightly` too.
export const versionMajorMinor = "2.5";
export const versionMajorMinor = "2.6";
/** The version of the TypeScript compiler release */
export const version = `${versionMajorMinor}.0`;
}
Expand Down Expand Up @@ -1543,16 +1543,20 @@ namespace ts {
}

export function normalizePath(path: string): string {
return normalizePathAndParts(path).path;
}

export function normalizePathAndParts(path: string): { path: string, parts: string[] } {
path = normalizeSlashes(path);
const rootLength = getRootLength(path);
const root = path.substr(0, rootLength);
const normalized = getNormalizedParts(path, rootLength);
if (normalized.length) {
const joinedParts = root + normalized.join(directorySeparator);
return pathEndsWithDirectorySeparator(path) ? joinedParts + directorySeparator : joinedParts;
const parts = getNormalizedParts(path, rootLength);
if (parts.length) {
const joinedParts = root + parts.join(directorySeparator);
return { path: pathEndsWithDirectorySeparator(path) ? joinedParts + directorySeparator : joinedParts, parts };
}
else {
return root;
return { path: root, parts };
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/compiler/declarationEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ namespace ts {
errorNameNode = declaration.name;
const format = TypeFormatFlags.UseTypeOfFunction |
TypeFormatFlags.WriteClassExpressionAsTypeLiteral |
TypeFormatFlags.UseTypeAliasValue |
(shouldUseResolverType ? TypeFormatFlags.AddUndefined : 0);
resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, format, writer);
errorNameNode = undefined;
Expand All @@ -368,7 +367,7 @@ namespace ts {
resolver.writeReturnTypeOfSignatureDeclaration(
signature,
enclosingDeclaration,
TypeFormatFlags.UseTypeOfFunction | TypeFormatFlags.UseTypeAliasValue | TypeFormatFlags.WriteClassExpressionAsTypeLiteral,
TypeFormatFlags.UseTypeOfFunction | TypeFormatFlags.WriteClassExpressionAsTypeLiteral,
writer);
errorNameNode = undefined;
}
Expand Down Expand Up @@ -633,7 +632,7 @@ namespace ts {
resolver.writeTypeOfExpression(
expr,
enclosingDeclaration,
TypeFormatFlags.UseTypeOfFunction | TypeFormatFlags.UseTypeAliasValue | TypeFormatFlags.WriteClassExpressionAsTypeLiteral,
TypeFormatFlags.UseTypeOfFunction | TypeFormatFlags.WriteClassExpressionAsTypeLiteral,
writer);
write(";");
writeLine();
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1912,6 +1912,10 @@
"category": "Error",
"code": 2560
},
"Base class expressions cannot reference class type parameters.": {
"category": "Error",
"code": 2561
},
"JSX element attributes type '{0}' may not be a union type.": {
"category": "Error",
"code": 2600
Expand Down
8 changes: 8 additions & 0 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,8 @@ namespace ts {
return emitPropertyAccessExpression(<PropertyAccessExpression>node);
case SyntaxKind.ElementAccessExpression:
return emitElementAccessExpression(<ElementAccessExpression>node);
case SyntaxKind.TypeCall:
return emitTypeCall(<TypeCallTypeNode>node);
case SyntaxKind.CallExpression:
return emitCallExpression(<CallExpression>node);
case SyntaxKind.NewExpression:
Expand Down Expand Up @@ -1240,6 +1242,12 @@ namespace ts {
write("]");
}

function emitTypeCall(node: TypeCallTypeNode) {
emit(node.type);
emitTypeArguments(node, node.typeArguments);
emitList(node, node.arguments, ListFormat.CallExpressionArguments);
}

function emitCallExpression(node: CallExpression) {
emitExpression(node.expression);
emitTypeArguments(node, node.typeArguments);
Expand Down
16 changes: 16 additions & 0 deletions src/compiler/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,22 @@ namespace ts {
: node;
}

export function createTypeCall(type: TypeNode, typeArguments: ReadonlyArray<TypeNode> | undefined, argumentsArray: ReadonlyArray<TypeNode>) {
const node = <TypeCallTypeNode>createSynthesizedNode(SyntaxKind.TypeCall);
node.type = parenthesizeElementTypeMember(type);
node.typeArguments = asNodeArray(typeArguments);
node.arguments = parenthesizeElementTypeMembers(createNodeArray(argumentsArray));
return node;
}

export function updateTypeCall(node: TypeCallTypeNode, type: TypeNode, typeArguments: ReadonlyArray<TypeNode> | undefined, argumentsArray: ReadonlyArray<TypeNode>) {
return node.type !== type
|| node.typeArguments !== typeArguments
|| node.arguments !== argumentsArray
? updateNode(createTypeCall(type, typeArguments, argumentsArray), node)
: node;
}

export function createCall(expression: Expression, typeArguments: ReadonlyArray<TypeNode> | undefined, argumentsArray: ReadonlyArray<Expression>) {
const node = <CallExpression>createSynthesizedNode(SyntaxKind.CallExpression);
node.expression = parenthesizeForAccess(expression);
Expand Down
11 changes: 6 additions & 5 deletions src/compiler/moduleNameResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ namespace ts {
let resolvedTypeReferenceDirective: ResolvedTypeReferenceDirective | undefined;
if (resolved) {
if (!options.preserveSymlinks) {
resolved = realpath(resolved, host, traceEnabled);
resolved = realPath(resolved, host, traceEnabled);
}

if (traceEnabled) {
Expand Down Expand Up @@ -741,20 +741,21 @@ namespace ts {

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

function realpath(path: string, host: ModuleResolutionHost, traceEnabled: boolean): string {
function realPath(path: string, host: ModuleResolutionHost, traceEnabled: boolean): string {
if (!host.realpath) {
return path;
}
Expand Down
54 changes: 49 additions & 5 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ namespace ts {
case SyntaxKind.ElementAccessExpression:
return visitNode(cbNode, (<ElementAccessExpression>node).expression) ||
visitNode(cbNode, (<ElementAccessExpression>node).argumentExpression);
case SyntaxKind.TypeCall:
return visitNode(cbNode, (<TypeCallTypeNode>node).type) ||
visitNodes(cbNode, cbNodes, (<TypeCallTypeNode>node).typeArguments) ||
visitNodes(cbNode, cbNodes, (<TypeCallTypeNode>node).arguments);
case SyntaxKind.CallExpression:
case SyntaxKind.NewExpression:
return visitNode(cbNode, (<CallExpression>node).expression) ||
Expand Down Expand Up @@ -2738,8 +2742,8 @@ namespace ts {
return token() === SyntaxKind.CloseParenToken || isStartOfParameter() || isStartOfType();
}

function parseJSDocPostfixTypeOrHigher(): TypeNode {
const type = parseNonArrayType();
function parseJSDocPostfixTypeOrHigher(typeNode?: TypeNode): TypeNode {
const type = typeNode || parseNonArrayType();
const kind = getKind(token());
if (!kind) return type;
nextToken();
Expand All @@ -2761,8 +2765,8 @@ namespace ts {
}
}

function parseArrayTypeOrHigher(): TypeNode {
let type = parseJSDocPostfixTypeOrHigher();
function parseArrayTypeOrHigher(typeNode?: TypeNode): TypeNode {
let type = parseJSDocPostfixTypeOrHigher(typeNode);
while (!scanner.hasPrecedingLineBreak() && parseOptional(SyntaxKind.OpenBracketToken)) {
if (isStartOfType()) {
const node = <IndexedAccessTypeNode>createNode(SyntaxKind.IndexedAccessType, type.pos);
Expand Down Expand Up @@ -2794,7 +2798,7 @@ namespace ts {
case SyntaxKind.KeyOfKeyword:
return parseTypeOperator(SyntaxKind.KeyOfKeyword);
}
return parseArrayTypeOrHigher();
return parseTypeCallRest();
}

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

// type equivalent of parseCallExpressionRest
function parseTypeCallRest(type?: TypeNode): TypeNode {
while (true) {
type = parseArrayTypeOrHigher(type);
if (token() === SyntaxKind.LessThanToken) {
// See if this is the start of a generic invocation. If so, consume it and
// keep checking for postfix expressions. Otherwise, it's just a '<' that's
// part of an arithmetic expression. Break out so we consume it higher in the
// stack.
const typeArguments = tryParse(parseTypeArgumentsInExpression);
if (!typeArguments) {
return type;
}

const callExpr = <TypeCallTypeNode>createNode(SyntaxKind.TypeCall, type.pos);
callExpr.type = type;
callExpr.typeArguments = typeArguments;
callExpr.arguments = parseTypeArgumentList();
type = finishNode(callExpr);
continue;
}
else if (token() === SyntaxKind.OpenParenToken) {
const callExpr = <TypeCallTypeNode>createNode(SyntaxKind.TypeCall, type.pos);
callExpr.type = type;
callExpr.arguments = parseTypeArgumentList();
type = finishNode(callExpr);
continue;
}

return type;
}
}

function parseTypeArgumentList() {
parseExpected(SyntaxKind.OpenParenToken);
const result = parseDelimitedList(ParsingContext.TypeArguments, parseType);
parseExpected(SyntaxKind.CloseParenToken);
return result;
}

function parseCallExpressionRest(expression: LeftHandSideExpression): LeftHandSideExpression {
while (true) {
expression = parseMemberExpressionRest(expression);
Expand Down
4 changes: 3 additions & 1 deletion src/compiler/transformers/es2015.ts
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ namespace ts {
outer.end = skipTrivia(currentText, node.pos);
setEmitFlags(outer, EmitFlags.NoComments);

return createParen(
const result = createParen(
createCall(
outer,
/*typeArguments*/ undefined,
Expand All @@ -849,6 +849,8 @@ namespace ts {
: []
)
);
addSyntheticLeadingComment(result, SyntaxKind.MultiLineCommentTrivia, "* @class ");
return result;
}

/**
Expand Down
Loading

0 comments on commit 6165eee

Please sign in to comment.