From 3c59481a92370f2c11c512f447bef21d6aec8f1f Mon Sep 17 00:00:00 2001 From: Zhengbo Li Date: Thu, 4 Jun 2015 16:06:12 -0700 Subject: [PATCH 01/13] Add missing overloads for texImage2D and texSubImage2D --- src/lib/dom.generated.d.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/lib/dom.generated.d.ts b/src/lib/dom.generated.d.ts index 5a4151c0c1c..e1f06f11009 100644 --- a/src/lib/dom.generated.d.ts +++ b/src/lib/dom.generated.d.ts @@ -7677,10 +7677,10 @@ declare var MediaQueryList: { interface MediaSource extends EventTarget { activeSourceBuffers: SourceBufferList; duration: number; - readyState: string; + readyState: number; sourceBuffers: SourceBufferList; addSourceBuffer(type: string): SourceBuffer; - endOfStream(error?: string): void; + endOfStream(error?: number): void; removeSourceBuffer(sourceBuffer: SourceBuffer): void; } @@ -8409,7 +8409,7 @@ declare var PopStateEvent: { interface Position { coords: Coordinates; - timestamp: Date; + timestamp: number; } declare var Position: { @@ -11090,9 +11090,17 @@ interface WebGLRenderingContext { stencilMaskSeparate(face: number, mask: number): void; stencilOp(fail: number, zfail: number, zpass: number): void; stencilOpSeparate(face: number, fail: number, zfail: number, zpass: number): void; + texImage2D(target: number, level: number, internalformat: number, width: number, height: number, border: number, format: number, type: number, pixels: ArrayBufferView): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, image: HTMLImageElement): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, canvas: HTMLCanvasElement): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, video: HTMLVideoElement): void; texImage2D(target: number, level: number, internalformat: number, format: number, type: number, pixels: ImageData): void; texParameterf(target: number, pname: number, param: number): void; texParameteri(target: number, pname: number, param: number): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, width: number, height: number, format: number, type: number, pixels: ArrayBufferView): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, image: HTMLImageElement): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, canvas: HTMLCanvasElement): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, video: HTMLVideoElement): void; texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, pixels: ImageData): void; uniform1f(location: WebGLUniformLocation, x: number): void; uniform1fv(location: WebGLUniformLocation, v: any): void; @@ -12332,10 +12340,11 @@ interface DocumentEvent { createEvent(eventInterface:"AriaRequestEvent"): AriaRequestEvent; createEvent(eventInterface:"AudioProcessingEvent"): AudioProcessingEvent; createEvent(eventInterface:"BeforeUnloadEvent"): BeforeUnloadEvent; + createEvent(eventInterface:"ClipboardEvent"): ClipboardEvent; createEvent(eventInterface:"CloseEvent"): CloseEvent; createEvent(eventInterface:"CommandEvent"): CommandEvent; createEvent(eventInterface:"CompositionEvent"): CompositionEvent; - createEvent(eventInterface: "CustomEvent"): CustomEvent; + createEvent(eventInterface:"CustomEvent"): CustomEvent; createEvent(eventInterface:"DeviceMotionEvent"): DeviceMotionEvent; createEvent(eventInterface:"DeviceOrientationEvent"): DeviceOrientationEvent; createEvent(eventInterface:"DragEvent"): DragEvent; @@ -12358,8 +12367,6 @@ interface DocumentEvent { createEvent(eventInterface:"MouseEvent"): MouseEvent; createEvent(eventInterface:"MouseEvents"): MouseEvent; createEvent(eventInterface:"MouseWheelEvent"): MouseWheelEvent; - createEvent(eventInterface:"MSGestureEvent"): MSGestureEvent; - createEvent(eventInterface:"MSPointerEvent"): MSPointerEvent; createEvent(eventInterface:"MutationEvent"): MutationEvent; createEvent(eventInterface:"MutationEvents"): MutationEvent; createEvent(eventInterface:"NavigationCompletedEvent"): NavigationCompletedEvent; @@ -12971,4 +12978,4 @@ declare function addEventListener(type: "unload", listener: (ev: Event) => any, declare function addEventListener(type: "volumechange", listener: (ev: Event) => any, useCapture?: boolean): void; declare function addEventListener(type: "waiting", listener: (ev: Event) => any, useCapture?: boolean): void; declare function addEventListener(type: "wheel", listener: (ev: WheelEvent) => any, useCapture?: boolean): void; -declare function addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; \ No newline at end of file +declare function addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; From 6f45524b9ff0f35ac75dd7889ee817bcbb14fe50 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 4 Jun 2015 16:35:30 -0700 Subject: [PATCH 02/13] Update LKG --- bin/lib.d.ts | 20 ++++++++++++++------ bin/lib.dom.d.ts | 21 ++++++++++++++------- bin/lib.es6.d.ts | 20 ++++++++++++++------ bin/tsc.js | 13 +++++++++---- bin/tsserver.js | 13 +++++++++---- bin/typescript.js | 18 ++++++++++++++---- bin/typescriptServices.js | 18 ++++++++++++++---- 7 files changed, 88 insertions(+), 35 deletions(-) diff --git a/bin/lib.d.ts b/bin/lib.d.ts index e583f1ac783..4724459e73d 100644 --- a/bin/lib.d.ts +++ b/bin/lib.d.ts @@ -11335,10 +11335,10 @@ declare var MediaQueryList: { interface MediaSource extends EventTarget { activeSourceBuffers: SourceBufferList; duration: number; - readyState: string; + readyState: number; sourceBuffers: SourceBufferList; addSourceBuffer(type: string): SourceBuffer; - endOfStream(error?: string): void; + endOfStream(error?: number): void; removeSourceBuffer(sourceBuffer: SourceBuffer): void; } @@ -12067,7 +12067,7 @@ declare var PopStateEvent: { interface Position { coords: Coordinates; - timestamp: Date; + timestamp: number; } declare var Position: { @@ -14748,9 +14748,17 @@ interface WebGLRenderingContext { stencilMaskSeparate(face: number, mask: number): void; stencilOp(fail: number, zfail: number, zpass: number): void; stencilOpSeparate(face: number, fail: number, zfail: number, zpass: number): void; + texImage2D(target: number, level: number, internalformat: number, width: number, height: number, border: number, format: number, type: number, pixels: ArrayBufferView): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, image: HTMLImageElement): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, canvas: HTMLCanvasElement): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, video: HTMLVideoElement): void; texImage2D(target: number, level: number, internalformat: number, format: number, type: number, pixels: ImageData): void; texParameterf(target: number, pname: number, param: number): void; texParameteri(target: number, pname: number, param: number): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, width: number, height: number, format: number, type: number, pixels: ArrayBufferView): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, image: HTMLImageElement): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, canvas: HTMLCanvasElement): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, video: HTMLVideoElement): void; texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, pixels: ImageData): void; uniform1f(location: WebGLUniformLocation, x: number): void; uniform1fv(location: WebGLUniformLocation, v: any): void; @@ -15990,10 +15998,11 @@ interface DocumentEvent { createEvent(eventInterface:"AriaRequestEvent"): AriaRequestEvent; createEvent(eventInterface:"AudioProcessingEvent"): AudioProcessingEvent; createEvent(eventInterface:"BeforeUnloadEvent"): BeforeUnloadEvent; + createEvent(eventInterface:"ClipboardEvent"): ClipboardEvent; createEvent(eventInterface:"CloseEvent"): CloseEvent; createEvent(eventInterface:"CommandEvent"): CommandEvent; createEvent(eventInterface:"CompositionEvent"): CompositionEvent; - createEvent(eventInterface: "CustomEvent"): CustomEvent; + createEvent(eventInterface:"CustomEvent"): CustomEvent; createEvent(eventInterface:"DeviceMotionEvent"): DeviceMotionEvent; createEvent(eventInterface:"DeviceOrientationEvent"): DeviceOrientationEvent; createEvent(eventInterface:"DragEvent"): DragEvent; @@ -16016,8 +16025,6 @@ interface DocumentEvent { createEvent(eventInterface:"MouseEvent"): MouseEvent; createEvent(eventInterface:"MouseEvents"): MouseEvent; createEvent(eventInterface:"MouseWheelEvent"): MouseWheelEvent; - createEvent(eventInterface:"MSGestureEvent"): MSGestureEvent; - createEvent(eventInterface:"MSPointerEvent"): MSPointerEvent; createEvent(eventInterface:"MutationEvent"): MutationEvent; createEvent(eventInterface:"MutationEvents"): MutationEvent; createEvent(eventInterface:"NavigationCompletedEvent"): NavigationCompletedEvent; @@ -16630,6 +16637,7 @@ declare function addEventListener(type: "volumechange", listener: (ev: Event) => declare function addEventListener(type: "waiting", listener: (ev: Event) => any, useCapture?: boolean): void; declare function addEventListener(type: "wheel", listener: (ev: WheelEvent) => any, useCapture?: boolean): void; declare function addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; + ///////////////////////////// /// WorkerGlobalScope APIs ///////////////////////////// diff --git a/bin/lib.dom.d.ts b/bin/lib.dom.d.ts index 142486a1662..7d83676acc7 100644 --- a/bin/lib.dom.d.ts +++ b/bin/lib.dom.d.ts @@ -10165,10 +10165,10 @@ declare var MediaQueryList: { interface MediaSource extends EventTarget { activeSourceBuffers: SourceBufferList; duration: number; - readyState: string; + readyState: number; sourceBuffers: SourceBufferList; addSourceBuffer(type: string): SourceBuffer; - endOfStream(error?: string): void; + endOfStream(error?: number): void; removeSourceBuffer(sourceBuffer: SourceBuffer): void; } @@ -10897,7 +10897,7 @@ declare var PopStateEvent: { interface Position { coords: Coordinates; - timestamp: Date; + timestamp: number; } declare var Position: { @@ -13578,9 +13578,17 @@ interface WebGLRenderingContext { stencilMaskSeparate(face: number, mask: number): void; stencilOp(fail: number, zfail: number, zpass: number): void; stencilOpSeparate(face: number, fail: number, zfail: number, zpass: number): void; + texImage2D(target: number, level: number, internalformat: number, width: number, height: number, border: number, format: number, type: number, pixels: ArrayBufferView): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, image: HTMLImageElement): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, canvas: HTMLCanvasElement): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, video: HTMLVideoElement): void; texImage2D(target: number, level: number, internalformat: number, format: number, type: number, pixels: ImageData): void; texParameterf(target: number, pname: number, param: number): void; texParameteri(target: number, pname: number, param: number): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, width: number, height: number, format: number, type: number, pixels: ArrayBufferView): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, image: HTMLImageElement): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, canvas: HTMLCanvasElement): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, video: HTMLVideoElement): void; texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, pixels: ImageData): void; uniform1f(location: WebGLUniformLocation, x: number): void; uniform1fv(location: WebGLUniformLocation, v: any): void; @@ -14820,10 +14828,11 @@ interface DocumentEvent { createEvent(eventInterface:"AriaRequestEvent"): AriaRequestEvent; createEvent(eventInterface:"AudioProcessingEvent"): AudioProcessingEvent; createEvent(eventInterface:"BeforeUnloadEvent"): BeforeUnloadEvent; + createEvent(eventInterface:"ClipboardEvent"): ClipboardEvent; createEvent(eventInterface:"CloseEvent"): CloseEvent; createEvent(eventInterface:"CommandEvent"): CommandEvent; createEvent(eventInterface:"CompositionEvent"): CompositionEvent; - createEvent(eventInterface: "CustomEvent"): CustomEvent; + createEvent(eventInterface:"CustomEvent"): CustomEvent; createEvent(eventInterface:"DeviceMotionEvent"): DeviceMotionEvent; createEvent(eventInterface:"DeviceOrientationEvent"): DeviceOrientationEvent; createEvent(eventInterface:"DragEvent"): DragEvent; @@ -14846,8 +14855,6 @@ interface DocumentEvent { createEvent(eventInterface:"MouseEvent"): MouseEvent; createEvent(eventInterface:"MouseEvents"): MouseEvent; createEvent(eventInterface:"MouseWheelEvent"): MouseWheelEvent; - createEvent(eventInterface:"MSGestureEvent"): MSGestureEvent; - createEvent(eventInterface:"MSPointerEvent"): MSPointerEvent; createEvent(eventInterface:"MutationEvent"): MutationEvent; createEvent(eventInterface:"MutationEvents"): MutationEvent; createEvent(eventInterface:"NavigationCompletedEvent"): NavigationCompletedEvent; @@ -15459,4 +15466,4 @@ declare function addEventListener(type: "unload", listener: (ev: Event) => any, declare function addEventListener(type: "volumechange", listener: (ev: Event) => any, useCapture?: boolean): void; declare function addEventListener(type: "waiting", listener: (ev: Event) => any, useCapture?: boolean): void; declare function addEventListener(type: "wheel", listener: (ev: WheelEvent) => any, useCapture?: boolean): void; -declare function addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; \ No newline at end of file +declare function addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; diff --git a/bin/lib.es6.d.ts b/bin/lib.es6.d.ts index d6ca7245140..396361a49f5 100644 --- a/bin/lib.es6.d.ts +++ b/bin/lib.es6.d.ts @@ -12716,10 +12716,10 @@ declare var MediaQueryList: { interface MediaSource extends EventTarget { activeSourceBuffers: SourceBufferList; duration: number; - readyState: string; + readyState: number; sourceBuffers: SourceBufferList; addSourceBuffer(type: string): SourceBuffer; - endOfStream(error?: string): void; + endOfStream(error?: number): void; removeSourceBuffer(sourceBuffer: SourceBuffer): void; } @@ -13448,7 +13448,7 @@ declare var PopStateEvent: { interface Position { coords: Coordinates; - timestamp: Date; + timestamp: number; } declare var Position: { @@ -16129,9 +16129,17 @@ interface WebGLRenderingContext { stencilMaskSeparate(face: number, mask: number): void; stencilOp(fail: number, zfail: number, zpass: number): void; stencilOpSeparate(face: number, fail: number, zfail: number, zpass: number): void; + texImage2D(target: number, level: number, internalformat: number, width: number, height: number, border: number, format: number, type: number, pixels: ArrayBufferView): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, image: HTMLImageElement): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, canvas: HTMLCanvasElement): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, video: HTMLVideoElement): void; texImage2D(target: number, level: number, internalformat: number, format: number, type: number, pixels: ImageData): void; texParameterf(target: number, pname: number, param: number): void; texParameteri(target: number, pname: number, param: number): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, width: number, height: number, format: number, type: number, pixels: ArrayBufferView): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, image: HTMLImageElement): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, canvas: HTMLCanvasElement): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, video: HTMLVideoElement): void; texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, pixels: ImageData): void; uniform1f(location: WebGLUniformLocation, x: number): void; uniform1fv(location: WebGLUniformLocation, v: any): void; @@ -17371,10 +17379,11 @@ interface DocumentEvent { createEvent(eventInterface:"AriaRequestEvent"): AriaRequestEvent; createEvent(eventInterface:"AudioProcessingEvent"): AudioProcessingEvent; createEvent(eventInterface:"BeforeUnloadEvent"): BeforeUnloadEvent; + createEvent(eventInterface:"ClipboardEvent"): ClipboardEvent; createEvent(eventInterface:"CloseEvent"): CloseEvent; createEvent(eventInterface:"CommandEvent"): CommandEvent; createEvent(eventInterface:"CompositionEvent"): CompositionEvent; - createEvent(eventInterface: "CustomEvent"): CustomEvent; + createEvent(eventInterface:"CustomEvent"): CustomEvent; createEvent(eventInterface:"DeviceMotionEvent"): DeviceMotionEvent; createEvent(eventInterface:"DeviceOrientationEvent"): DeviceOrientationEvent; createEvent(eventInterface:"DragEvent"): DragEvent; @@ -17397,8 +17406,6 @@ interface DocumentEvent { createEvent(eventInterface:"MouseEvent"): MouseEvent; createEvent(eventInterface:"MouseEvents"): MouseEvent; createEvent(eventInterface:"MouseWheelEvent"): MouseWheelEvent; - createEvent(eventInterface:"MSGestureEvent"): MSGestureEvent; - createEvent(eventInterface:"MSPointerEvent"): MSPointerEvent; createEvent(eventInterface:"MutationEvent"): MutationEvent; createEvent(eventInterface:"MutationEvents"): MutationEvent; createEvent(eventInterface:"NavigationCompletedEvent"): NavigationCompletedEvent; @@ -18011,6 +18018,7 @@ declare function addEventListener(type: "volumechange", listener: (ev: Event) => declare function addEventListener(type: "waiting", listener: (ev: Event) => any, useCapture?: boolean): void; declare function addEventListener(type: "wheel", listener: (ev: WheelEvent) => any, useCapture?: boolean): void; declare function addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; + ///////////////////////////// /// WorkerGlobalScope APIs ///////////////////////////// diff --git a/bin/tsc.js b/bin/tsc.js index a6d28976046..e7a41e8aa7e 100644 --- a/bin/tsc.js +++ b/bin/tsc.js @@ -21533,7 +21533,12 @@ var ts; return result; } function parenthesizeForAccess(expr) { - if (ts.isLeftHandSideExpression(expr) && expr.kind !== 159 && expr.kind !== 7) { + while (expr.kind === 161) { + expr = expr.expression; + } + if (ts.isLeftHandSideExpression(expr) && + expr.kind !== 159 && + expr.kind !== 7) { return expr; } var node = ts.createSynthesizedNode(162); @@ -21740,7 +21745,7 @@ var ts; } } function emitParenExpression(node) { - if (!node.parent || node.parent.kind !== 164) { + if (!ts.nodeIsSynthesized(node) && node.parent.kind !== 164) { if (node.expression.kind === 161) { var operand = node.expression.expression; while (operand.kind == 161) { @@ -23727,7 +23732,7 @@ var ts; emitDeclarationName(node); write("\", "); emitDeclarationName(node); - write(")"); + write(");"); } emitExportMemberAssignments(node.name); } @@ -23835,7 +23840,7 @@ var ts; emitDeclarationName(node); write("\", "); emitDeclarationName(node); - write(")"); + write(");"); } emitExportMemberAssignments(node.name); } diff --git a/bin/tsserver.js b/bin/tsserver.js index 194f0768196..8536491127d 100644 --- a/bin/tsserver.js +++ b/bin/tsserver.js @@ -21923,7 +21923,12 @@ var ts; return result; } function parenthesizeForAccess(expr) { - if (ts.isLeftHandSideExpression(expr) && expr.kind !== 159 && expr.kind !== 7) { + while (expr.kind === 161) { + expr = expr.expression; + } + if (ts.isLeftHandSideExpression(expr) && + expr.kind !== 159 && + expr.kind !== 7) { return expr; } var node = ts.createSynthesizedNode(162); @@ -22130,7 +22135,7 @@ var ts; } } function emitParenExpression(node) { - if (!node.parent || node.parent.kind !== 164) { + if (!ts.nodeIsSynthesized(node) && node.parent.kind !== 164) { if (node.expression.kind === 161) { var operand = node.expression.expression; while (operand.kind == 161) { @@ -24117,7 +24122,7 @@ var ts; emitDeclarationName(node); write("\", "); emitDeclarationName(node); - write(")"); + write(");"); } emitExportMemberAssignments(node.name); } @@ -24225,7 +24230,7 @@ var ts; emitDeclarationName(node); write("\", "); emitDeclarationName(node); - write(")"); + write(");"); } emitExportMemberAssignments(node.name); } diff --git a/bin/typescript.js b/bin/typescript.js index dac610e2504..b393f2ee881 100644 --- a/bin/typescript.js +++ b/bin/typescript.js @@ -25628,6 +25628,11 @@ var ts; return result; } function parenthesizeForAccess(expr) { + // When diagnosing whether the expression needs parentheses, the decision should be based + // on the innermost expression in a chain of nested type assertions. + while (expr.kind === 161 /* TypeAssertionExpression */) { + expr = expr.expression; + } // isLeftHandSideExpression is almost the correct criterion for when it is not necessary // to parenthesize the expression before a dot. The known exceptions are: // @@ -25636,7 +25641,9 @@ var ts; // NumberLiteral // 1.x -> not the same as (1).x // - if (ts.isLeftHandSideExpression(expr) && expr.kind !== 159 /* NewExpression */ && expr.kind !== 7 /* NumericLiteral */) { + if (ts.isLeftHandSideExpression(expr) && + expr.kind !== 159 /* NewExpression */ && + expr.kind !== 7 /* NumericLiteral */) { return expr; } var node = ts.createSynthesizedNode(162 /* ParenthesizedExpression */); @@ -25867,7 +25874,10 @@ var ts; } } function emitParenExpression(node) { - if (!node.parent || node.parent.kind !== 164 /* ArrowFunction */) { + // If the node is synthesized, it means the emitter put the parentheses there, + // not the user. If we didn't want them, the emitter would not have put them + // there. + if (!ts.nodeIsSynthesized(node) && node.parent.kind !== 164 /* ArrowFunction */) { if (node.expression.kind === 161 /* TypeAssertionExpression */) { var operand = node.expression.expression; // Make sure we consider all nested cast expressions, e.g.: @@ -28149,7 +28159,7 @@ var ts; emitDeclarationName(node); write("\", "); emitDeclarationName(node); - write(")"); + write(");"); } emitExportMemberAssignments(node.name); } @@ -28259,7 +28269,7 @@ var ts; emitDeclarationName(node); write("\", "); emitDeclarationName(node); - write(")"); + write(");"); } emitExportMemberAssignments(node.name); } diff --git a/bin/typescriptServices.js b/bin/typescriptServices.js index dac610e2504..b393f2ee881 100644 --- a/bin/typescriptServices.js +++ b/bin/typescriptServices.js @@ -25628,6 +25628,11 @@ var ts; return result; } function parenthesizeForAccess(expr) { + // When diagnosing whether the expression needs parentheses, the decision should be based + // on the innermost expression in a chain of nested type assertions. + while (expr.kind === 161 /* TypeAssertionExpression */) { + expr = expr.expression; + } // isLeftHandSideExpression is almost the correct criterion for when it is not necessary // to parenthesize the expression before a dot. The known exceptions are: // @@ -25636,7 +25641,9 @@ var ts; // NumberLiteral // 1.x -> not the same as (1).x // - if (ts.isLeftHandSideExpression(expr) && expr.kind !== 159 /* NewExpression */ && expr.kind !== 7 /* NumericLiteral */) { + if (ts.isLeftHandSideExpression(expr) && + expr.kind !== 159 /* NewExpression */ && + expr.kind !== 7 /* NumericLiteral */) { return expr; } var node = ts.createSynthesizedNode(162 /* ParenthesizedExpression */); @@ -25867,7 +25874,10 @@ var ts; } } function emitParenExpression(node) { - if (!node.parent || node.parent.kind !== 164 /* ArrowFunction */) { + // If the node is synthesized, it means the emitter put the parentheses there, + // not the user. If we didn't want them, the emitter would not have put them + // there. + if (!ts.nodeIsSynthesized(node) && node.parent.kind !== 164 /* ArrowFunction */) { if (node.expression.kind === 161 /* TypeAssertionExpression */) { var operand = node.expression.expression; // Make sure we consider all nested cast expressions, e.g.: @@ -28149,7 +28159,7 @@ var ts; emitDeclarationName(node); write("\", "); emitDeclarationName(node); - write(")"); + write(");"); } emitExportMemberAssignments(node.name); } @@ -28259,7 +28269,7 @@ var ts; emitDeclarationName(node); write("\", "); emitDeclarationName(node); - write(")"); + write(");"); } emitExportMemberAssignments(node.name); } From 7c8a50336d6c1bb56d0daef91cf52d05fc12ff56 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 3 Jun 2015 14:55:42 -0700 Subject: [PATCH 03/13] emit module name for system modules, add moduleName argument to 'transpile' function Conflicts: src/services/services.ts --- src/compiler/emitter.ts | 10 +++++++--- src/compiler/parser.ts | 2 +- src/compiler/types.ts | 2 +- src/services/services.ts | 7 +++++-- .../baselines/reference/systemModule12.errors.txt | 10 ++++++++++ tests/baselines/reference/systemModule12.js | 14 ++++++++++++++ tests/cases/compiler/systemModule12.ts | 5 +++++ 7 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 tests/baselines/reference/systemModule12.errors.txt create mode 100644 tests/baselines/reference/systemModule12.js create mode 100644 tests/cases/compiler/systemModule12.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 165f0da5cfd..7d0a29f9e26 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5477,7 +5477,11 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { Debug.assert(!exportFunctionForFile); // make sure that name of 'exports' function does not conflict with existing identifiers exportFunctionForFile = makeUniqueName("exports"); - write("System.register(["); + write("System.register("); + if (node.moduleName) { + write(`"${node.moduleName}", `); + } + write("[") for (let i = 0; i < externalImports.length; ++i) { let text = getExternalModuleNameText(externalImports[i]); if (i !== 0) { @@ -5563,8 +5567,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { writeLine(); write("define("); - if (node.amdModuleName) { - write("\"" + node.amdModuleName + "\", "); + if (node.moduleName) { + write("\"" + node.moduleName + "\", "); } emitAMDDependencies(node, /*includeNonAmdDependencies*/ true); write(") {"); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 055fc1b6f74..07da065c1ae 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4820,7 +4820,7 @@ module ts { sourceFile.referencedFiles = referencedFiles; sourceFile.amdDependencies = amdDependencies; - sourceFile.amdModuleName = amdModuleName; + sourceFile.moduleName = amdModuleName; } function setExternalModuleIndicator(sourceFile: SourceFile) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 1db5e57d298..1a72e9fc94a 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1001,7 +1001,7 @@ module ts { text: string; amdDependencies: {path: string; name: string}[]; - amdModuleName: string; + moduleName: string; referencedFiles: FileReference[]; hasNoDefaultLib: boolean; diff --git a/src/services/services.ts b/src/services/services.ts index 6a497c87307..ece411ae1ea 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -735,7 +735,7 @@ module ts { public endOfFileToken: Node; public amdDependencies: { name: string; path: string }[]; - public amdModuleName: string; + public moduleName: string; public referencedFiles: FileReference[]; public syntacticDiagnostics: Diagnostic[]; @@ -1766,7 +1766,7 @@ module ts { * - noLib = true * - noResolve = true */ - export function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]): string { + export function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[], moduleName?: string): string { let options = compilerOptions ? clone(compilerOptions) : getDefaultCompilerOptions(); options.isolatedModules = true; @@ -1785,6 +1785,9 @@ module ts { // Parse let inputFileName = fileName || "module.ts"; let sourceFile = createSourceFile(inputFileName, input, options.target); + if (moduleName) { + sourceFile.moduleName = moduleName; + } // Store syntactic diagnostics if (diagnostics && sourceFile.parseDiagnostics) { diff --git a/tests/baselines/reference/systemModule12.errors.txt b/tests/baselines/reference/systemModule12.errors.txt new file mode 100644 index 00000000000..5c89e2e65d6 --- /dev/null +++ b/tests/baselines/reference/systemModule12.errors.txt @@ -0,0 +1,10 @@ +tests/cases/compiler/systemModule12.ts(3,15): error TS2307: Cannot find module 'file1'. + + +==== tests/cases/compiler/systemModule12.ts (1 errors) ==== + + /// + import n from 'file1' + ~~~~~~~ +!!! error TS2307: Cannot find module 'file1'. + \ No newline at end of file diff --git a/tests/baselines/reference/systemModule12.js b/tests/baselines/reference/systemModule12.js new file mode 100644 index 00000000000..0b5f5a3e850 --- /dev/null +++ b/tests/baselines/reference/systemModule12.js @@ -0,0 +1,14 @@ +//// [systemModule12.ts] + +/// +import n from 'file1' + + +//// [systemModule12.js] +System.register("NamedModule", [], function(exports_1) { + return { + setters:[], + execute: function() { + } + } +}); diff --git a/tests/cases/compiler/systemModule12.ts b/tests/cases/compiler/systemModule12.ts new file mode 100644 index 00000000000..690fabc0a28 --- /dev/null +++ b/tests/cases/compiler/systemModule12.ts @@ -0,0 +1,5 @@ +// @module: system +// @isolatedModules: true + +/// +import n from 'file1' From 3c630aa247e079af94a6dd045a7d07cad7cb2b26 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 4 Jun 2015 22:22:25 -0700 Subject: [PATCH 04/13] added tests --- tests/cases/unittests/transpile.ts | 33 +++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/tests/cases/unittests/transpile.ts b/tests/cases/unittests/transpile.ts index c906c03a9e0..7aa9106880b 100644 --- a/tests/cases/unittests/transpile.ts +++ b/tests/cases/unittests/transpile.ts @@ -3,9 +3,9 @@ module ts { describe("Transpile", () => { - function runTest(input: string, compilerOptions: ts.CompilerOptions = {}, expectedOutput?: string, expectedDiagnosticCodes: number[] = []): void { + function runTest(input: string, compilerOptions: ts.CompilerOptions = {}, moduleName?: string, expectedOutput?: string, expectedDiagnosticCodes: number[] = []): void { let diagnostics: Diagnostic[] = []; - let result = transpile(input, compilerOptions, "file.ts", diagnostics); + let result = transpile(input, compilerOptions, "file.ts", diagnostics, moduleName); for (let i = 0; i < expectedDiagnosticCodes.length; i++) { assert.equal(expectedDiagnosticCodes[i], diagnostics[i] && diagnostics[i].code, `Could not find expeced diagnostic.`); @@ -19,41 +19,54 @@ module ts { it("Generates correct compilerOptions diagnostics", () => { // Expecting 5047: "Option 'isolatedModules' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher." - runTest(`var x = 0;`, {}, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ [5047]); + runTest(`var x = 0;`, {}, /*moduleName*/undefined, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ [5047]); }); it("Generates no diagnostics with valid inputs", () => { // No errors - runTest(`var x = 0;`, { module: ModuleKind.CommonJS }, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ []); + runTest(`var x = 0;`, { module: ModuleKind.CommonJS }, /*moduleName*/undefined, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ []); }); it("Generates no diagnostics for missing file references", () => { runTest(`/// var x = 0;`, - { module: ModuleKind.CommonJS }, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ []); + { module: ModuleKind.CommonJS }, /*moduleName*/undefined, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ []); }); it("Generates no diagnostics for missing module imports", () => { runTest(`import {a} from "module2";`, - { module: ModuleKind.CommonJS }, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ []); + { module: ModuleKind.CommonJS }, /*moduleName*/undefined, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ []); }); it("Generates expected syntactic diagnostics", () => { runTest(`a b`, - { module: ModuleKind.CommonJS }, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ [1005]); /// 1005: ';' Expected + { module: ModuleKind.CommonJS }, /*moduleName*/undefined, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ [1005]); /// 1005: ';' Expected }); it("Does not generate semantic diagnostics", () => { runTest(`var x: string = 0;`, - { module: ModuleKind.CommonJS }, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ []); + { module: ModuleKind.CommonJS }, /*moduleName*/undefined, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ []); }); it("Generates module output", () => { - runTest(`var x = 0;`, { module: ModuleKind.AMD }, `define(["require", "exports"], function (require, exports) {\r\n var x = 0;\r\n});\r\n`); + runTest(`var x = 0;`, { module: ModuleKind.AMD }, /*moduleName*/undefined, `define(["require", "exports"], function (require, exports) {\r\n var x = 0;\r\n});\r\n`); }); it("Uses correct newLine character", () => { - runTest(`var x = 0;`, { module: ModuleKind.CommonJS, newLine: NewLineKind.LineFeed }, `var x = 0;\n`, /*expectedDiagnosticCodes*/ []); + runTest(`var x = 0;`, { module: ModuleKind.CommonJS, newLine: NewLineKind.LineFeed }, /*moduleName*/undefined, `var x = 0;\n`, /*expectedDiagnosticCodes*/ []); + }); + + it("Sets module name", () => { + let output = + `System.register("NamedModule", [], function(exports_1) {\n var x;\n` + + ` return {\n` + + ` setters:[],\n` + + ` execute: function() {\n` + + ` var x = 1;\n` + + ` }\n` + + ` }\n` + + `});\n`; + runTest("var x = 1;", { module: ModuleKind.System, newLine: NewLineKind.LineFeed }, "NamedModule", output) }); }); } From 26a1ed60171236ea9af4dcc2991537d134eb3164 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 8 Jun 2015 18:31:56 -0700 Subject: [PATCH 05/13] move temp declarations out of object literal --- src/compiler/emitter.ts | 2 +- tests/baselines/reference/systemModule8.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 165f0da5cfd..5919e62633a 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5327,10 +5327,10 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { emitSetters(exportStarFunction); writeLine(); emitExecute(node, startIndex); - emitTempDeclarations(/*newLine*/ true) decreaseIndent(); writeLine(); write("}"); // return + emitTempDeclarations(/*newLine*/ true) } function emitSetters(exportStarFunction: string) { diff --git a/tests/baselines/reference/systemModule8.js b/tests/baselines/reference/systemModule8.js index 578814d0ab2..14f7a4c6fbe 100644 --- a/tests/baselines/reference/systemModule8.js +++ b/tests/baselines/reference/systemModule8.js @@ -66,6 +66,6 @@ System.register([], function(exports_1) { exports_1("x", x = _b[_i][0]); } } - var _a; } + var _a; }); From 185b2aff088b0c8ad0bf6b04b7511f0bbd5ed146 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 8 Jun 2015 22:46:59 -0700 Subject: [PATCH 06/13] added missing semicolon --- src/compiler/emitter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 5919e62633a..857a5404524 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5330,7 +5330,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { decreaseIndent(); writeLine(); write("}"); // return - emitTempDeclarations(/*newLine*/ true) + emitTempDeclarations(/*newLine*/ true); } function emitSetters(exportStarFunction: string) { From d0763060c9c837d6c3a235e58271313e54cb3146 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 10 Jun 2015 12:32:24 -0700 Subject: [PATCH 07/13] added more tests --- tests/baselines/reference/systemModule13.js | 21 ++++++++++++ .../reference/systemModule13.symbols | 17 ++++++++++ .../baselines/reference/systemModule13.types | 32 +++++++++++++++++++ tests/cases/compiler/systemModule13.ts | 5 +++ 4 files changed, 75 insertions(+) create mode 100644 tests/baselines/reference/systemModule13.js create mode 100644 tests/baselines/reference/systemModule13.symbols create mode 100644 tests/baselines/reference/systemModule13.types create mode 100644 tests/cases/compiler/systemModule13.ts diff --git a/tests/baselines/reference/systemModule13.js b/tests/baselines/reference/systemModule13.js new file mode 100644 index 00000000000..c66e123c738 --- /dev/null +++ b/tests/baselines/reference/systemModule13.js @@ -0,0 +1,21 @@ +//// [systemModule13.ts] + +export let [x,y,z] = [1, 2, 3]; +export const {a: z0, b: {c: z1}} = {a: true, b: {c: "123"}}; +for ([x] of [[1]]) {} + +//// [systemModule13.js] +System.register([], function(exports_1) { + var x, y, z, z0, z1; + return { + setters:[], + execute: function() { + _a = [1, 2, 3], exports_1("x", x = _a[0]), exports_1("y", y = _a[1]), exports_1("z", z = _a[2]); + _b = { a: true, b: { c: "123" } }, exports_1("z0", z0 = _b.a), exports_1("z1", z1 = _b.b.c); + for (var _i = 0, _c = [[1]]; _i < _c.length; _i++) { + exports_1("x", x = _c[_i][0]); + } + } + } + var _a, _b; +}); diff --git a/tests/baselines/reference/systemModule13.symbols b/tests/baselines/reference/systemModule13.symbols new file mode 100644 index 00000000000..d9e64335c2b --- /dev/null +++ b/tests/baselines/reference/systemModule13.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/systemModule13.ts === + +export let [x,y,z] = [1, 2, 3]; +>x : Symbol(x, Decl(systemModule13.ts, 1, 12)) +>y : Symbol(y, Decl(systemModule13.ts, 1, 14)) +>z : Symbol(z, Decl(systemModule13.ts, 1, 16)) + +export const {a: z0, b: {c: z1}} = {a: true, b: {c: "123"}}; +>z0 : Symbol(z0, Decl(systemModule13.ts, 2, 14)) +>z1 : Symbol(z1, Decl(systemModule13.ts, 2, 25)) +>a : Symbol(a, Decl(systemModule13.ts, 2, 36)) +>b : Symbol(b, Decl(systemModule13.ts, 2, 44)) +>c : Symbol(c, Decl(systemModule13.ts, 2, 49)) + +for ([x] of [[1]]) {} +>x : Symbol(x, Decl(systemModule13.ts, 1, 12)) + diff --git a/tests/baselines/reference/systemModule13.types b/tests/baselines/reference/systemModule13.types new file mode 100644 index 00000000000..35f22be98b8 --- /dev/null +++ b/tests/baselines/reference/systemModule13.types @@ -0,0 +1,32 @@ +=== tests/cases/compiler/systemModule13.ts === + +export let [x,y,z] = [1, 2, 3]; +>x : number +>y : number +>z : number +>[1, 2, 3] : [number, number, number] +>1 : number +>2 : number +>3 : number + +export const {a: z0, b: {c: z1}} = {a: true, b: {c: "123"}}; +>a : any +>z0 : boolean +>b : any +>c : any +>z1 : string +>{a: true, b: {c: "123"}} : { a: boolean; b: { c: string; }; } +>a : boolean +>true : boolean +>b : { c: string; } +>{c: "123"} : { c: string; } +>c : string +>"123" : string + +for ([x] of [[1]]) {} +>[x] : number[] +>x : number +>[[1]] : number[][] +>[1] : number[] +>1 : number + diff --git a/tests/cases/compiler/systemModule13.ts b/tests/cases/compiler/systemModule13.ts new file mode 100644 index 00000000000..2f92d99ab21 --- /dev/null +++ b/tests/cases/compiler/systemModule13.ts @@ -0,0 +1,5 @@ +// @module: system + +export let [x,y,z] = [1, 2, 3]; +export const {a: z0, b: {c: z1}} = {a: true, b: {c: "123"}}; +for ([x] of [[1]]) {} \ No newline at end of file From 25c093673cceb508a4d7f855754c0b9006a0e5f8 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 3 Jun 2015 13:48:34 -0700 Subject: [PATCH 08/13] introduce FileMap to store mappings with filenames as keys --- src/compiler/core.ts | 32 +++++++++++++++++++++++ src/compiler/program.ts | 17 ++++++------ src/services/services.ts | 56 +++++++++++++++++++++------------------- src/services/shims.ts | 10 ++++++- 4 files changed, 80 insertions(+), 35 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index c753f7ff42d..bba10a635e4 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -15,6 +15,38 @@ module ts { True = -1 } + export class FileMap { + private files: Map = {}; + + constructor(private getCanonicalFileName: (fileName: string) => string) { + } + + public set(fileName: string, value: T) { + this.files[this.normalizeKey(fileName)] = value; + } + + public get(fileName: string) { + return this.files[this.normalizeKey(fileName)]; + } + + public contains(fileName: string) { + return hasProperty(this.files, this.normalizeKey(fileName)); + } + + public delete(fileName: string) { + let key = this.normalizeKey(fileName); + delete this.files[key]; + } + + public forEachValue(f: (value: T) => void) { + forEachValue(this.files, f); + } + + private normalizeKey(key: string) { + return this.getCanonicalFileName(normalizeSlashes(key)); + } + } + export const enum Comparison { LessThan = -1, EqualTo = 0, diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 0af94b3d854..fa794bbb77e 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -143,7 +143,6 @@ module ts { export function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program { let program: Program; let files: SourceFile[] = []; - let filesByName: Map = {}; let diagnostics = createDiagnosticCollection(); let seenNoDefaultLib = options.noLib; let commonSourceDirectory: string; @@ -153,6 +152,8 @@ module ts { let start = new Date().getTime(); host = host || createCompilerHost(options); + let filesByName: FileMap = new FileMap(host.getCanonicalFileName); + forEach(rootNames, name => processRootFile(name, false)); if (!seenNoDefaultLib) { processRootFile(host.getDefaultLibFileName(options), true); @@ -233,8 +234,7 @@ module ts { } function getSourceFile(fileName: string) { - fileName = host.getCanonicalFileName(normalizeSlashes(fileName)); - return hasProperty(filesByName, fileName) ? filesByName[fileName] : undefined; + return filesByName.get(fileName); } function getDiagnosticsHelper(sourceFile: SourceFile, getDiagnostics: (sourceFile: SourceFile) => Diagnostic[]): Diagnostic[] { @@ -352,19 +352,19 @@ module ts { // Get source file from normalized fileName function findSourceFile(fileName: string, isDefaultLib: boolean, refFile?: SourceFile, refStart?: number, refLength?: number): SourceFile { let canonicalName = host.getCanonicalFileName(normalizeSlashes(fileName)); - if (hasProperty(filesByName, canonicalName)) { + if (filesByName.contains(canonicalName)) { // We've already looked for this file, use cached result return getSourceFileFromCache(fileName, canonicalName, /*useAbsolutePath*/ false); } else { let normalizedAbsolutePath = getNormalizedAbsolutePath(fileName, host.getCurrentDirectory()); let canonicalAbsolutePath = host.getCanonicalFileName(normalizedAbsolutePath); - if (hasProperty(filesByName, canonicalAbsolutePath)) { + if (filesByName.contains(canonicalAbsolutePath)) { return getSourceFileFromCache(normalizedAbsolutePath, canonicalAbsolutePath, /*useAbsolutePath*/ true); } // We haven't looked for this file, do so now and cache result - let file = filesByName[canonicalName] = host.getSourceFile(fileName, options.target, hostErrorMessage => { + let file = host.getSourceFile(fileName, options.target, hostErrorMessage => { if (refFile) { diagnostics.add(createFileDiagnostic(refFile, refStart, refLength, Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); @@ -373,11 +373,12 @@ module ts { diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } }); + filesByName.set(canonicalName, file); if (file) { seenNoDefaultLib = seenNoDefaultLib || file.hasNoDefaultLib; // Set the source file for normalized absolute path - filesByName[canonicalAbsolutePath] = file; + filesByName.set(canonicalAbsolutePath, file); if (!options.noResolve) { let basePath = getDirectoryPath(fileName); @@ -396,7 +397,7 @@ module ts { } function getSourceFileFromCache(fileName: string, canonicalName: string, useAbsolutePath: boolean): SourceFile { - let file = filesByName[canonicalName]; + let file = filesByName.get(canonicalName); if (file && host.useCaseSensitiveFileNames()) { let sourceFileName = useAbsolutePath ? getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory()) : file.fileName; if (canonicalName !== sourceFileName) { diff --git a/src/services/services.ts b/src/services/services.ts index ece411ae1ea..b6f95c2f13a 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -960,6 +960,7 @@ module ts { log? (s: string): void; trace? (s: string): void; error? (s: string): void; + useCaseSensitiveFileNames? (): boolean; } // @@ -1630,12 +1631,12 @@ module ts { // at each language service public entry point, since we don't know when // set of scripts handled by the host changes. class HostCache { - private fileNameToEntry: Map; + private fileNameToEntry: FileMap; private _compilationSettings: CompilerOptions; - constructor(private host: LanguageServiceHost, private getCanonicalFileName: (fileName: string) => string) { + constructor(private host: LanguageServiceHost, getCanonicalFileName: (fileName: string) => string) { // script id => script index - this.fileNameToEntry = {}; + this.fileNameToEntry = new FileMap(getCanonicalFileName); // Initialize the list with the root file names let rootFileNames = host.getScriptFileNames(); @@ -1651,10 +1652,6 @@ module ts { return this._compilationSettings; } - private normalizeFileName(fileName: string): string { - return this.getCanonicalFileName(normalizeSlashes(fileName)); - } - private createEntry(fileName: string) { let entry: HostFileInformation; let scriptSnapshot = this.host.getScriptSnapshot(fileName); @@ -1666,15 +1663,16 @@ module ts { }; } - return this.fileNameToEntry[this.normalizeFileName(fileName)] = entry; + this.fileNameToEntry.set(fileName, entry); + return entry; } private getEntry(fileName: string): HostFileInformation { - return lookUp(this.fileNameToEntry, this.normalizeFileName(fileName)); + return this.fileNameToEntry.get(fileName); } private contains(fileName: string): boolean { - return hasProperty(this.fileNameToEntry, this.normalizeFileName(fileName)); + return this.fileNameToEntry.contains(fileName); } public getOrCreateEntry(fileName: string): HostFileInformation { @@ -1688,10 +1686,9 @@ module ts { public getRootFileNames(): string[] { let fileNames: string[] = []; - forEachKey(this.fileNameToEntry, key => { - let entry = this.getEntry(key); - if (entry) { - fileNames.push(entry.hostFileName); + this.fileNameToEntry.forEachValue(value => { + if (value) { + fileNames.push(value.hostFileName); } }); @@ -1885,20 +1882,28 @@ module ts { return createLanguageServiceSourceFile(sourceFile.fileName, scriptSnapshot, sourceFile.languageVersion, version, /*setNodeParents:*/ true); } - export function createDocumentRegistry(): DocumentRegistry { + function createGetCanonicalFileName(useCaseSensitivefileNames: boolean): (fileName: string) => string { + return useCaseSensitivefileNames + ? ((fileName) => fileName) + : ((fileName) => fileName.toLowerCase()); + } + + + export function createDocumentRegistry(useCaseSensitiveFileNames?: boolean): DocumentRegistry { // Maps from compiler setting target (ES3, ES5, etc.) to all the cached documents we have // for those settings. - let buckets: Map> = {}; + let buckets: Map> = {}; + let getCanonicalFileName = createGetCanonicalFileName(useCaseSensitiveFileNames || false); function getKeyFromCompilationSettings(settings: CompilerOptions): string { return "_" + settings.target; // + "|" + settings.propagateEnumConstantoString() } - function getBucketForCompilationSettings(settings: CompilerOptions, createIfMissing: boolean): Map { + function getBucketForCompilationSettings(settings: CompilerOptions, createIfMissing: boolean): FileMap { let key = getKeyFromCompilationSettings(settings); let bucket = lookUp(buckets, key); if (!bucket && createIfMissing) { - buckets[key] = bucket = {}; + buckets[key] = bucket = new FileMap(getCanonicalFileName); } return bucket; } @@ -1908,7 +1913,7 @@ module ts { let entries = lookUp(buckets, name); let sourceFiles: { name: string; refCount: number; references: string[]; }[] = []; for (let i in entries) { - let entry = entries[i]; + let entry = entries.get(i); sourceFiles.push({ name: i, refCount: entry.languageServiceRefCount, @@ -1940,18 +1945,19 @@ module ts { acquiring: boolean): SourceFile { let bucket = getBucketForCompilationSettings(compilationSettings, /*createIfMissing*/ true); - let entry = lookUp(bucket, fileName); + let entry = bucket.get(fileName); if (!entry) { Debug.assert(acquiring, "How could we be trying to update a document that the registry doesn't have?"); // Have never seen this file with these settings. Create a new source file for it. let sourceFile = createLanguageServiceSourceFile(fileName, scriptSnapshot, compilationSettings.target, version, /*setNodeParents:*/ false); - bucket[fileName] = entry = { + entry = { sourceFile: sourceFile, languageServiceRefCount: 0, owners: [] }; + bucket.set(fileName, entry); } else { // We have an entry for this file. However, it may be for a different version of @@ -1979,12 +1985,12 @@ module ts { let bucket = getBucketForCompilationSettings(compilationSettings, false); Debug.assert(bucket !== undefined); - let entry = lookUp(bucket, fileName); + let entry = bucket.get(fileName); entry.languageServiceRefCount--; Debug.assert(entry.languageServiceRefCount >= 0); if (entry.languageServiceRefCount === 0) { - delete bucket[fileName]; + bucket.delete(fileName); } } @@ -2412,9 +2418,7 @@ module ts { } } - function getCanonicalFileName(fileName: string) { - return useCaseSensitivefileNames ? fileName : fileName.toLowerCase(); - } + let getCanonicalFileName = createGetCanonicalFileName(useCaseSensitivefileNames); function getValidSourceFile(fileName: string): SourceFile { fileName = normalizeSlashes(fileName); diff --git a/src/services/shims.ts b/src/services/shims.ts index d3f59737538..4dfab444cde 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -56,6 +56,7 @@ module ts { getDefaultLibFileName(options: string): string; getNewLine?(): string; getProjectVersion?(): string; + useCaseSensitiveFileNames?(): boolean; } /** Public interface of the the of a config service shim instance.*/ @@ -270,6 +271,10 @@ module ts { return this.shimHost.getProjectVersion(); } + public useCaseSensitiveFileNames(): boolean { + return this.shimHost.useCaseSensitiveFileNames && this.useCaseSensitiveFileNames(); + } + public getCompilationSettings(): CompilerOptions { var settingsJson = this.shimHost.getCompilationSettings(); if (settingsJson == null || settingsJson == "") { @@ -909,7 +914,7 @@ module ts { export class TypeScriptServicesFactory implements ShimFactory { private _shims: Shim[] = []; - private documentRegistry: DocumentRegistry = createDocumentRegistry(); + private documentRegistry: DocumentRegistry; /* * Returns script API version. @@ -920,6 +925,9 @@ module ts { public createLanguageServiceShim(host: LanguageServiceShimHost): LanguageServiceShim { try { + if (this.documentRegistry === undefined) { + this.documentRegistry = createDocumentRegistry(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames()); + } var hostAdapter = new LanguageServiceShimHostAdapter(host); var languageService = createLanguageService(hostAdapter, this.documentRegistry); return new LanguageServiceShimObject(this, host, languageService); From b4f1df2afa039e3c31fd833a2483de5124cb4f90 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 3 Jun 2015 15:22:17 -0700 Subject: [PATCH 09/13] address PR feedback --- src/compiler/core.ts | 38 +++++++++++++++++++++----------------- src/compiler/program.ts | 2 +- src/compiler/types.ts | 8 ++++++++ src/services/services.ts | 6 +++--- src/services/shims.ts | 2 +- 5 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index bba10a635e4..1f04f9968ca 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -15,35 +15,39 @@ module ts { True = -1 } - export class FileMap { - private files: Map = {}; - - constructor(private getCanonicalFileName: (fileName: string) => string) { + export function createFileMap(getCanonicalFileName: (fileName: string) => string): FileMap { + let files: Map = {}; + return { + get, + set, + contains, + delete: deleteItem, + forEachValue: forEachValueInMap } - public set(fileName: string, value: T) { - this.files[this.normalizeKey(fileName)] = value; + function set(fileName: string, value: T) { + files[normalizeKey(fileName)] = value; } - public get(fileName: string) { - return this.files[this.normalizeKey(fileName)]; + function get(fileName: string) { + return files[normalizeKey(fileName)]; } - public contains(fileName: string) { - return hasProperty(this.files, this.normalizeKey(fileName)); + function contains(fileName: string) { + return hasProperty(files, normalizeKey(fileName)); } - public delete(fileName: string) { - let key = this.normalizeKey(fileName); - delete this.files[key]; + function deleteItem (fileName: string) { + let key = normalizeKey(fileName); + delete files[key]; } - public forEachValue(f: (value: T) => void) { - forEachValue(this.files, f); + function forEachValueInMap(f: (value: T) => void) { + forEachValue(files, f); } - private normalizeKey(key: string) { - return this.getCanonicalFileName(normalizeSlashes(key)); + function normalizeKey(key: string) { + return getCanonicalFileName(normalizeSlashes(key)); } } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index fa794bbb77e..5c40230484a 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -152,7 +152,7 @@ module ts { let start = new Date().getTime(); host = host || createCompilerHost(options); - let filesByName: FileMap = new FileMap(host.getCanonicalFileName); + let filesByName = createFileMap(host.getCanonicalFileName); forEach(rootNames, name => processRootFile(name, false)); if (!seenNoDefaultLib) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 1a72e9fc94a..c3ce9d44ae3 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3,6 +3,14 @@ module ts { [index: string]: T; } + export interface FileMap { + get(fileName: string): T; + set(fileName: string, value: T): void; + contains(fileName: string): boolean; + delete(fileName: string): void; + forEachValue(f: (v: T) => void): void; + } + export interface TextRange { pos: number; end: number; diff --git a/src/services/services.ts b/src/services/services.ts index b6f95c2f13a..2329eeb2e83 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1636,7 +1636,7 @@ module ts { constructor(private host: LanguageServiceHost, getCanonicalFileName: (fileName: string) => string) { // script id => script index - this.fileNameToEntry = new FileMap(getCanonicalFileName); + this.fileNameToEntry = createFileMap(getCanonicalFileName); // Initialize the list with the root file names let rootFileNames = host.getScriptFileNames(); @@ -1893,7 +1893,7 @@ module ts { // Maps from compiler setting target (ES3, ES5, etc.) to all the cached documents we have // for those settings. let buckets: Map> = {}; - let getCanonicalFileName = createGetCanonicalFileName(useCaseSensitiveFileNames || false); + let getCanonicalFileName = createGetCanonicalFileName(!!useCaseSensitiveFileNames); function getKeyFromCompilationSettings(settings: CompilerOptions): string { return "_" + settings.target; // + "|" + settings.propagateEnumConstantoString() @@ -1903,7 +1903,7 @@ module ts { let key = getKeyFromCompilationSettings(settings); let bucket = lookUp(buckets, key); if (!bucket && createIfMissing) { - buckets[key] = bucket = new FileMap(getCanonicalFileName); + buckets[key] = bucket = createFileMap(getCanonicalFileName); } return bucket; } diff --git a/src/services/shims.ts b/src/services/shims.ts index 4dfab444cde..004393fb3b5 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -272,7 +272,7 @@ module ts { } public useCaseSensitiveFileNames(): boolean { - return this.shimHost.useCaseSensitiveFileNames && this.useCaseSensitiveFileNames(); + return this.shimHost.useCaseSensitiveFileNames ? this.shimHost.useCaseSensitiveFileNames() : false; } public getCompilationSettings(): CompilerOptions { From 522248a042cd08594a2de4e0475c0f72f4bf9ba1 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 4 Jun 2015 11:18:05 -0700 Subject: [PATCH 10/13] rename 'FileMap.delete' to 'FileMap.remove' --- src/compiler/core.ts | 4 ++-- src/compiler/types.ts | 2 +- src/services/services.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 1f04f9968ca..d9a1fc5368a 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -21,7 +21,7 @@ module ts { get, set, contains, - delete: deleteItem, + remove, forEachValue: forEachValueInMap } @@ -37,7 +37,7 @@ module ts { return hasProperty(files, normalizeKey(fileName)); } - function deleteItem (fileName: string) { + function remove (fileName: string) { let key = normalizeKey(fileName); delete files[key]; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index c3ce9d44ae3..e1f565969d8 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -7,7 +7,7 @@ module ts { get(fileName: string): T; set(fileName: string, value: T): void; contains(fileName: string): boolean; - delete(fileName: string): void; + remove(fileName: string): void; forEachValue(f: (v: T) => void): void; } diff --git a/src/services/services.ts b/src/services/services.ts index 2329eeb2e83..521c6db155a 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1990,7 +1990,7 @@ module ts { Debug.assert(entry.languageServiceRefCount >= 0); if (entry.languageServiceRefCount === 0) { - bucket.delete(fileName); + bucket.remove(fileName); } } From 54edbaeea72af18b7536f1d4564a7b5164dc6515 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Mon, 15 Jun 2015 16:28:29 -0700 Subject: [PATCH 11/13] Parse class member with a missing identifier in the presence of a modifier --- src/compiler/parser.ts | 4 +-- ...lassMemberWithMissingIdentifier.errors.txt | 12 ++++++++ .../classMemberWithMissingIdentifier.js | 12 ++++++++ ...assMemberWithMissingIdentifier2.errors.txt | 30 +++++++++++++++++++ .../classMemberWithMissingIdentifier2.js | 13 ++++++++ .../classMemberWithMissingIdentifier.ts | 3 ++ .../classMemberWithMissingIdentifier2.ts | 3 ++ 7 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/classMemberWithMissingIdentifier.errors.txt create mode 100644 tests/baselines/reference/classMemberWithMissingIdentifier.js create mode 100644 tests/baselines/reference/classMemberWithMissingIdentifier2.errors.txt create mode 100644 tests/baselines/reference/classMemberWithMissingIdentifier2.js create mode 100644 tests/cases/compiler/classMemberWithMissingIdentifier.ts create mode 100644 tests/cases/compiler/classMemberWithMissingIdentifier2.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 07da065c1ae..35ef6393748 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4207,7 +4207,7 @@ module ts { return parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers); } - if (decorators) { + if (decorators || modifiers) { // treat this as a property declaration with a missing name. let name = createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected); return parsePropertyDeclaration(fullStart, decorators, modifiers, name, /*questionToken*/ undefined); @@ -4729,7 +4729,7 @@ module ts { case SyntaxKind.ImportKeyword: return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers); default: - if (decorators) { + if (decorators || modifiers) { // We reached this point because we encountered an AtToken and assumed a declaration would // follow. For recovery and error reporting purposes, return an incomplete declaration. let node = createMissingNode(SyntaxKind.MissingDeclaration, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected); diff --git a/tests/baselines/reference/classMemberWithMissingIdentifier.errors.txt b/tests/baselines/reference/classMemberWithMissingIdentifier.errors.txt new file mode 100644 index 00000000000..4bbc2d8167d --- /dev/null +++ b/tests/baselines/reference/classMemberWithMissingIdentifier.errors.txt @@ -0,0 +1,12 @@ +tests/cases/compiler/classMemberWithMissingIdentifier.ts(2,11): error TS1146: Declaration expected. +tests/cases/compiler/classMemberWithMissingIdentifier.ts(2,12): error TS1005: '=' expected. + + +==== tests/cases/compiler/classMemberWithMissingIdentifier.ts (2 errors) ==== + class C { + public {}; + +!!! error TS1146: Declaration expected. + ~ +!!! error TS1005: '=' expected. + } \ No newline at end of file diff --git a/tests/baselines/reference/classMemberWithMissingIdentifier.js b/tests/baselines/reference/classMemberWithMissingIdentifier.js new file mode 100644 index 00000000000..cd1825d0da0 --- /dev/null +++ b/tests/baselines/reference/classMemberWithMissingIdentifier.js @@ -0,0 +1,12 @@ +//// [classMemberWithMissingIdentifier.ts] +class C { + public {}; +} + +//// [classMemberWithMissingIdentifier.js] +var C = (function () { + function C() { + this. = {}; + } + return C; +})(); diff --git a/tests/baselines/reference/classMemberWithMissingIdentifier2.errors.txt b/tests/baselines/reference/classMemberWithMissingIdentifier2.errors.txt new file mode 100644 index 00000000000..b21e062e3b0 --- /dev/null +++ b/tests/baselines/reference/classMemberWithMissingIdentifier2.errors.txt @@ -0,0 +1,30 @@ +tests/cases/compiler/classMemberWithMissingIdentifier2.ts(2,11): error TS1146: Declaration expected. +tests/cases/compiler/classMemberWithMissingIdentifier2.ts(2,12): error TS1005: '=' expected. +tests/cases/compiler/classMemberWithMissingIdentifier2.ts(2,14): error TS2304: Cannot find name 'name'. +tests/cases/compiler/classMemberWithMissingIdentifier2.ts(2,18): error TS1005: ']' expected. +tests/cases/compiler/classMemberWithMissingIdentifier2.ts(2,19): error TS2304: Cannot find name 'string'. +tests/cases/compiler/classMemberWithMissingIdentifier2.ts(2,25): error TS1005: ',' expected. +tests/cases/compiler/classMemberWithMissingIdentifier2.ts(2,26): error TS1136: Property assignment expected. +tests/cases/compiler/classMemberWithMissingIdentifier2.ts(2,27): error TS2304: Cannot find name 'VariableDeclaration'. + + +==== tests/cases/compiler/classMemberWithMissingIdentifier2.ts (8 errors) ==== + class C { + public {[name:string]:VariableDeclaration}; + +!!! error TS1146: Declaration expected. + ~ +!!! error TS1005: '=' expected. + ~~~~ +!!! error TS2304: Cannot find name 'name'. + ~ +!!! error TS1005: ']' expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'string'. + ~ +!!! error TS1005: ',' expected. + ~ +!!! error TS1136: Property assignment expected. + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'VariableDeclaration'. + } \ No newline at end of file diff --git a/tests/baselines/reference/classMemberWithMissingIdentifier2.js b/tests/baselines/reference/classMemberWithMissingIdentifier2.js new file mode 100644 index 00000000000..e8494755b22 --- /dev/null +++ b/tests/baselines/reference/classMemberWithMissingIdentifier2.js @@ -0,0 +1,13 @@ +//// [classMemberWithMissingIdentifier2.ts] +class C { + public {[name:string]:VariableDeclaration}; +} + +//// [classMemberWithMissingIdentifier2.js] +var C = (function () { + function C() { + this. = (_a = {}, _a[name] = string, _a.VariableDeclaration = VariableDeclaration, _a); + var _a; + } + return C; +})(); diff --git a/tests/cases/compiler/classMemberWithMissingIdentifier.ts b/tests/cases/compiler/classMemberWithMissingIdentifier.ts new file mode 100644 index 00000000000..01ba223f4c4 --- /dev/null +++ b/tests/cases/compiler/classMemberWithMissingIdentifier.ts @@ -0,0 +1,3 @@ +class C { + public {}; +} \ No newline at end of file diff --git a/tests/cases/compiler/classMemberWithMissingIdentifier2.ts b/tests/cases/compiler/classMemberWithMissingIdentifier2.ts new file mode 100644 index 00000000000..e1618659797 --- /dev/null +++ b/tests/cases/compiler/classMemberWithMissingIdentifier2.ts @@ -0,0 +1,3 @@ +class C { + public {[name:string]:VariableDeclaration}; +} \ No newline at end of file From 41e39735e88301c38ca89e98e0cdfaa42d8301e0 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Tue, 16 Jun 2015 17:06:00 -0700 Subject: [PATCH 12/13] Make resolveName ignore export specifiers without calling getSymbol --- src/compiler/checker.ts | 33 ++++++++++++++----- ...rtSpecifierAndExportedMemberDeclaration.js | 15 +++++++++ ...cifierAndExportedMemberDeclaration.symbols | 27 +++++++++++++++ ...pecifierAndExportedMemberDeclaration.types | 27 +++++++++++++++ ...cifierAndLocalMemberDeclaration.errors.txt | 18 ++++++++++ ...xportSpecifierAndLocalMemberDeclaration.js | 15 +++++++++ ...rtSpecifierReferencingOuterDeclaration1.js | 8 +++++ ...cifierReferencingOuterDeclaration1.symbols | 14 ++++++++ ...pecifierReferencingOuterDeclaration1.types | 14 ++++++++ ...rtSpecifierReferencingOuterDeclaration2.js | 11 +++++++ ...cifierReferencingOuterDeclaration2.symbols | 14 ++++++++ ...pecifierReferencingOuterDeclaration2.types | 14 ++++++++ ...ierReferencingOuterDeclaration3.errors.txt | 13 ++++++++ ...rtSpecifierReferencingOuterDeclaration3.js | 10 ++++++ ...ierReferencingOuterDeclaration4.errors.txt | 13 ++++++++ ...rtSpecifierReferencingOuterDeclaration4.js | 13 ++++++++ ...rtSpecifierAndExportedMemberDeclaration.ts | 12 +++++++ ...xportSpecifierAndLocalMemberDeclaration.ts | 12 +++++++ ...rtSpecifierReferencingOuterDeclaration1.ts | 5 +++ ...rtSpecifierReferencingOuterDeclaration2.ts | 7 ++++ ...rtSpecifierReferencingOuterDeclaration3.ts | 7 ++++ ...rtSpecifierReferencingOuterDeclaration4.ts | 9 +++++ 22 files changed, 303 insertions(+), 8 deletions(-) create mode 100644 tests/baselines/reference/exportSpecifierAndExportedMemberDeclaration.js create mode 100644 tests/baselines/reference/exportSpecifierAndExportedMemberDeclaration.symbols create mode 100644 tests/baselines/reference/exportSpecifierAndExportedMemberDeclaration.types create mode 100644 tests/baselines/reference/exportSpecifierAndLocalMemberDeclaration.errors.txt create mode 100644 tests/baselines/reference/exportSpecifierAndLocalMemberDeclaration.js create mode 100644 tests/baselines/reference/exportSpecifierReferencingOuterDeclaration1.js create mode 100644 tests/baselines/reference/exportSpecifierReferencingOuterDeclaration1.symbols create mode 100644 tests/baselines/reference/exportSpecifierReferencingOuterDeclaration1.types create mode 100644 tests/baselines/reference/exportSpecifierReferencingOuterDeclaration2.js create mode 100644 tests/baselines/reference/exportSpecifierReferencingOuterDeclaration2.symbols create mode 100644 tests/baselines/reference/exportSpecifierReferencingOuterDeclaration2.types create mode 100644 tests/baselines/reference/exportSpecifierReferencingOuterDeclaration3.errors.txt create mode 100644 tests/baselines/reference/exportSpecifierReferencingOuterDeclaration3.js create mode 100644 tests/baselines/reference/exportSpecifierReferencingOuterDeclaration4.errors.txt create mode 100644 tests/baselines/reference/exportSpecifierReferencingOuterDeclaration4.js create mode 100644 tests/cases/compiler/exportSpecifierAndExportedMemberDeclaration.ts create mode 100644 tests/cases/compiler/exportSpecifierAndLocalMemberDeclaration.ts create mode 100644 tests/cases/compiler/exportSpecifierReferencingOuterDeclaration1.ts create mode 100644 tests/cases/compiler/exportSpecifierReferencingOuterDeclaration2.ts create mode 100644 tests/cases/compiler/exportSpecifierReferencingOuterDeclaration3.ts create mode 100644 tests/cases/compiler/exportSpecifierReferencingOuterDeclaration4.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8ee39ab18f3..d296ea5fa22 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -344,21 +344,38 @@ module ts { case SyntaxKind.SourceFile: if (!isExternalModule(location)) break; case SyntaxKind.ModuleDeclaration: - if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & SymbolFlags.ModuleMember)) { - if (result.flags & meaning || !(result.flags & SymbolFlags.Alias && getDeclarationOfAliasSymbol(result).kind === SyntaxKind.ExportSpecifier)) { - break loop; - } - result = undefined; - } - else if (location.kind === SyntaxKind.SourceFile || + let moduleExports = getSymbolOfNode(location).exports; + if (location.kind === SyntaxKind.SourceFile || (location.kind === SyntaxKind.ModuleDeclaration && (location).name.kind === SyntaxKind.StringLiteral)) { - result = getSymbolOfNode(location).exports["default"]; + + // It's an external module. Because of module/namespace merging, a module's exports are in scope, + // yet we never want to treat an export specifier as putting a member in scope. Therefore, + // if the name we find is purely an export specifier, it is not actually considered in scope. + // Two things to note about this: + // 1. We have to check this without calling getSymbol. The problem with calling getSymbol + // on an export specifier is that it might find the export specifier itself, and try to + // resolve it as an alias. This will cause the checker to consider the export specifier + // a circular alias reference when it might not be. + // 2. We check === SymbolFlags.Alias in order to check that the symbol is *purely* + // an alias. If we used &, we'd be throwing out symbols that have non alias aspects, + // which is not the desired behavior. + if (hasProperty(moduleExports, name) && + moduleExports[name].flags === SymbolFlags.Alias && + getDeclarationOfKind(moduleExports[name], SyntaxKind.ExportSpecifier)) { + break; + } + + result = moduleExports["default"]; let localSymbol = getLocalSymbolForExportDefault(result); if (result && localSymbol && (result.flags & meaning) && localSymbol.name === name) { break loop; } result = undefined; } + + if (result = getSymbol(moduleExports, name, meaning & SymbolFlags.ModuleMember)) { + break loop; + } break; case SyntaxKind.EnumDeclaration: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & SymbolFlags.EnumMember)) { diff --git a/tests/baselines/reference/exportSpecifierAndExportedMemberDeclaration.js b/tests/baselines/reference/exportSpecifierAndExportedMemberDeclaration.js new file mode 100644 index 00000000000..3fc40121011 --- /dev/null +++ b/tests/baselines/reference/exportSpecifierAndExportedMemberDeclaration.js @@ -0,0 +1,15 @@ +//// [exportSpecifierAndExportedMemberDeclaration.ts] +declare module "m2" { + export module X { + interface I { } + } + function Y(); + export { Y as X }; + function Z(): X.I; +} + +declare module "m2" { + function Z2(): X.I; +} + +//// [exportSpecifierAndExportedMemberDeclaration.js] diff --git a/tests/baselines/reference/exportSpecifierAndExportedMemberDeclaration.symbols b/tests/baselines/reference/exportSpecifierAndExportedMemberDeclaration.symbols new file mode 100644 index 00000000000..7e2de735c47 --- /dev/null +++ b/tests/baselines/reference/exportSpecifierAndExportedMemberDeclaration.symbols @@ -0,0 +1,27 @@ +=== tests/cases/compiler/exportSpecifierAndExportedMemberDeclaration.ts === +declare module "m2" { + export module X { +>X : Symbol(X, Decl(exportSpecifierAndExportedMemberDeclaration.ts, 0, 21), Decl(exportSpecifierAndExportedMemberDeclaration.ts, 5, 12)) + + interface I { } +>I : Symbol(I, Decl(exportSpecifierAndExportedMemberDeclaration.ts, 1, 21)) + } + function Y(); +>Y : Symbol(Y, Decl(exportSpecifierAndExportedMemberDeclaration.ts, 3, 5)) + + export { Y as X }; +>Y : Symbol(X, Decl(exportSpecifierAndExportedMemberDeclaration.ts, 0, 21), Decl(exportSpecifierAndExportedMemberDeclaration.ts, 5, 12)) +>X : Symbol(X, Decl(exportSpecifierAndExportedMemberDeclaration.ts, 0, 21), Decl(exportSpecifierAndExportedMemberDeclaration.ts, 5, 12)) + + function Z(): X.I; +>Z : Symbol(Z, Decl(exportSpecifierAndExportedMemberDeclaration.ts, 5, 22)) +>X : Symbol(X, Decl(exportSpecifierAndExportedMemberDeclaration.ts, 0, 21), Decl(exportSpecifierAndExportedMemberDeclaration.ts, 5, 12)) +>I : Symbol(X.I, Decl(exportSpecifierAndExportedMemberDeclaration.ts, 1, 21)) +} + +declare module "m2" { + function Z2(): X.I; +>Z2 : Symbol(Z2, Decl(exportSpecifierAndExportedMemberDeclaration.ts, 9, 21)) +>X : Symbol(X, Decl(exportSpecifierAndExportedMemberDeclaration.ts, 0, 21), Decl(exportSpecifierAndExportedMemberDeclaration.ts, 5, 12)) +>I : Symbol(X.I, Decl(exportSpecifierAndExportedMemberDeclaration.ts, 1, 21)) +} diff --git a/tests/baselines/reference/exportSpecifierAndExportedMemberDeclaration.types b/tests/baselines/reference/exportSpecifierAndExportedMemberDeclaration.types new file mode 100644 index 00000000000..931552819c7 --- /dev/null +++ b/tests/baselines/reference/exportSpecifierAndExportedMemberDeclaration.types @@ -0,0 +1,27 @@ +=== tests/cases/compiler/exportSpecifierAndExportedMemberDeclaration.ts === +declare module "m2" { + export module X { +>X : () => any + + interface I { } +>I : I + } + function Y(); +>Y : () => any + + export { Y as X }; +>Y : () => any +>X : () => any + + function Z(): X.I; +>Z : () => X.I +>X : any +>I : X.I +} + +declare module "m2" { + function Z2(): X.I; +>Z2 : () => X.I +>X : any +>I : X.I +} diff --git a/tests/baselines/reference/exportSpecifierAndLocalMemberDeclaration.errors.txt b/tests/baselines/reference/exportSpecifierAndLocalMemberDeclaration.errors.txt new file mode 100644 index 00000000000..eb444919f2c --- /dev/null +++ b/tests/baselines/reference/exportSpecifierAndLocalMemberDeclaration.errors.txt @@ -0,0 +1,18 @@ +tests/cases/compiler/exportSpecifierAndLocalMemberDeclaration.ts(11,20): error TS2503: Cannot find namespace 'X'. + + +==== tests/cases/compiler/exportSpecifierAndLocalMemberDeclaration.ts (1 errors) ==== + declare module "m2" { + module X { + interface I { } + } + function Y(); + export { Y as X }; + function Z(): X.I; + } + + declare module "m2" { + function Z2(): X.I; + ~ +!!! error TS2503: Cannot find namespace 'X'. + } \ No newline at end of file diff --git a/tests/baselines/reference/exportSpecifierAndLocalMemberDeclaration.js b/tests/baselines/reference/exportSpecifierAndLocalMemberDeclaration.js new file mode 100644 index 00000000000..d99ff3627ed --- /dev/null +++ b/tests/baselines/reference/exportSpecifierAndLocalMemberDeclaration.js @@ -0,0 +1,15 @@ +//// [exportSpecifierAndLocalMemberDeclaration.ts] +declare module "m2" { + module X { + interface I { } + } + function Y(); + export { Y as X }; + function Z(): X.I; +} + +declare module "m2" { + function Z2(): X.I; +} + +//// [exportSpecifierAndLocalMemberDeclaration.js] diff --git a/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration1.js b/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration1.js new file mode 100644 index 00000000000..003956e2822 --- /dev/null +++ b/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration1.js @@ -0,0 +1,8 @@ +//// [exportSpecifierReferencingOuterDeclaration1.ts] +declare module X { export interface bar { } } +declare module "m" { + export { X }; + export function foo(): X.bar; +} + +//// [exportSpecifierReferencingOuterDeclaration1.js] diff --git a/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration1.symbols b/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration1.symbols new file mode 100644 index 00000000000..16abde86d32 --- /dev/null +++ b/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration1.symbols @@ -0,0 +1,14 @@ +=== tests/cases/compiler/exportSpecifierReferencingOuterDeclaration1.ts === +declare module X { export interface bar { } } +>X : Symbol(X, Decl(exportSpecifierReferencingOuterDeclaration1.ts, 0, 0)) +>bar : Symbol(bar, Decl(exportSpecifierReferencingOuterDeclaration1.ts, 0, 18)) + +declare module "m" { + export { X }; +>X : Symbol(X, Decl(exportSpecifierReferencingOuterDeclaration1.ts, 2, 12)) + + export function foo(): X.bar; +>foo : Symbol(foo, Decl(exportSpecifierReferencingOuterDeclaration1.ts, 2, 17)) +>X : Symbol(X, Decl(exportSpecifierReferencingOuterDeclaration1.ts, 0, 0)) +>bar : Symbol(X.bar, Decl(exportSpecifierReferencingOuterDeclaration1.ts, 0, 18)) +} diff --git a/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration1.types b/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration1.types new file mode 100644 index 00000000000..be03554a1b0 --- /dev/null +++ b/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration1.types @@ -0,0 +1,14 @@ +=== tests/cases/compiler/exportSpecifierReferencingOuterDeclaration1.ts === +declare module X { export interface bar { } } +>X : any +>bar : bar + +declare module "m" { + export { X }; +>X : any + + export function foo(): X.bar; +>foo : () => X.bar +>X : any +>bar : X.bar +} diff --git a/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration2.js b/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration2.js new file mode 100644 index 00000000000..e8e96784083 --- /dev/null +++ b/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration2.js @@ -0,0 +1,11 @@ +//// [tests/cases/compiler/exportSpecifierReferencingOuterDeclaration2.ts] //// + +//// [exportSpecifierReferencingOuterDeclaration2_A.ts] +declare module X { export interface bar { } } + +//// [exportSpecifierReferencingOuterDeclaration2_B.ts] +export { X }; +export declare function foo(): X.bar; + +//// [exportSpecifierReferencingOuterDeclaration2_A.js] +//// [exportSpecifierReferencingOuterDeclaration2_B.js] diff --git a/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration2.symbols b/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration2.symbols new file mode 100644 index 00000000000..9a57645b1cb --- /dev/null +++ b/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration2.symbols @@ -0,0 +1,14 @@ +=== tests/cases/compiler/exportSpecifierReferencingOuterDeclaration2_A.ts === +declare module X { export interface bar { } } +>X : Symbol(X, Decl(exportSpecifierReferencingOuterDeclaration2_A.ts, 0, 0)) +>bar : Symbol(bar, Decl(exportSpecifierReferencingOuterDeclaration2_A.ts, 0, 18)) + +=== tests/cases/compiler/exportSpecifierReferencingOuterDeclaration2_B.ts === +export { X }; +>X : Symbol(X, Decl(exportSpecifierReferencingOuterDeclaration2_B.ts, 0, 8)) + +export declare function foo(): X.bar; +>foo : Symbol(foo, Decl(exportSpecifierReferencingOuterDeclaration2_B.ts, 0, 13)) +>X : Symbol(X, Decl(exportSpecifierReferencingOuterDeclaration2_A.ts, 0, 0)) +>bar : Symbol(X.bar, Decl(exportSpecifierReferencingOuterDeclaration2_A.ts, 0, 18)) + diff --git a/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration2.types b/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration2.types new file mode 100644 index 00000000000..fa59948c116 --- /dev/null +++ b/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration2.types @@ -0,0 +1,14 @@ +=== tests/cases/compiler/exportSpecifierReferencingOuterDeclaration2_A.ts === +declare module X { export interface bar { } } +>X : any +>bar : bar + +=== tests/cases/compiler/exportSpecifierReferencingOuterDeclaration2_B.ts === +export { X }; +>X : any + +export declare function foo(): X.bar; +>foo : () => X.bar +>X : any +>bar : X.bar + diff --git a/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration3.errors.txt b/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration3.errors.txt new file mode 100644 index 00000000000..e144c48bea4 --- /dev/null +++ b/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration3.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/exportSpecifierReferencingOuterDeclaration3.ts(6,30): error TS2305: Module 'X' has no exported member 'bar'. + + +==== tests/cases/compiler/exportSpecifierReferencingOuterDeclaration3.ts (1 errors) ==== + declare module X { export interface bar { } } + declare module "m" { + module X { export interface foo { } } + export { X }; + export function foo(): X.foo; + export function bar(): X.bar; // error + ~~~ +!!! error TS2305: Module 'X' has no exported member 'bar'. + } \ No newline at end of file diff --git a/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration3.js b/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration3.js new file mode 100644 index 00000000000..0f6fff977da --- /dev/null +++ b/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration3.js @@ -0,0 +1,10 @@ +//// [exportSpecifierReferencingOuterDeclaration3.ts] +declare module X { export interface bar { } } +declare module "m" { + module X { export interface foo { } } + export { X }; + export function foo(): X.foo; + export function bar(): X.bar; // error +} + +//// [exportSpecifierReferencingOuterDeclaration3.js] diff --git a/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration4.errors.txt b/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration4.errors.txt new file mode 100644 index 00000000000..6ac67c70d17 --- /dev/null +++ b/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration4.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/exportSpecifierReferencingOuterDeclaration2_B.ts(4,34): error TS2305: Module 'X' has no exported member 'bar'. + + +==== tests/cases/compiler/exportSpecifierReferencingOuterDeclaration2_A.ts (0 errors) ==== + declare module X { export interface bar { } } + +==== tests/cases/compiler/exportSpecifierReferencingOuterDeclaration2_B.ts (1 errors) ==== + declare module X { export interface foo { } } + export { X }; + export declare function foo(): X.foo; + export declare function bar(): X.bar; // error + ~~~ +!!! error TS2305: Module 'X' has no exported member 'bar'. \ No newline at end of file diff --git a/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration4.js b/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration4.js new file mode 100644 index 00000000000..4edb5f711a6 --- /dev/null +++ b/tests/baselines/reference/exportSpecifierReferencingOuterDeclaration4.js @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/exportSpecifierReferencingOuterDeclaration4.ts] //// + +//// [exportSpecifierReferencingOuterDeclaration2_A.ts] +declare module X { export interface bar { } } + +//// [exportSpecifierReferencingOuterDeclaration2_B.ts] +declare module X { export interface foo { } } +export { X }; +export declare function foo(): X.foo; +export declare function bar(): X.bar; // error + +//// [exportSpecifierReferencingOuterDeclaration2_A.js] +//// [exportSpecifierReferencingOuterDeclaration2_B.js] diff --git a/tests/cases/compiler/exportSpecifierAndExportedMemberDeclaration.ts b/tests/cases/compiler/exportSpecifierAndExportedMemberDeclaration.ts new file mode 100644 index 00000000000..1c20ffb0437 --- /dev/null +++ b/tests/cases/compiler/exportSpecifierAndExportedMemberDeclaration.ts @@ -0,0 +1,12 @@ +declare module "m2" { + export module X { + interface I { } + } + function Y(); + export { Y as X }; + function Z(): X.I; +} + +declare module "m2" { + function Z2(): X.I; +} \ No newline at end of file diff --git a/tests/cases/compiler/exportSpecifierAndLocalMemberDeclaration.ts b/tests/cases/compiler/exportSpecifierAndLocalMemberDeclaration.ts new file mode 100644 index 00000000000..5f942a75a74 --- /dev/null +++ b/tests/cases/compiler/exportSpecifierAndLocalMemberDeclaration.ts @@ -0,0 +1,12 @@ +declare module "m2" { + module X { + interface I { } + } + function Y(); + export { Y as X }; + function Z(): X.I; +} + +declare module "m2" { + function Z2(): X.I; +} \ No newline at end of file diff --git a/tests/cases/compiler/exportSpecifierReferencingOuterDeclaration1.ts b/tests/cases/compiler/exportSpecifierReferencingOuterDeclaration1.ts new file mode 100644 index 00000000000..e3d0a9000ab --- /dev/null +++ b/tests/cases/compiler/exportSpecifierReferencingOuterDeclaration1.ts @@ -0,0 +1,5 @@ +declare module X { export interface bar { } } +declare module "m" { + export { X }; + export function foo(): X.bar; +} \ No newline at end of file diff --git a/tests/cases/compiler/exportSpecifierReferencingOuterDeclaration2.ts b/tests/cases/compiler/exportSpecifierReferencingOuterDeclaration2.ts new file mode 100644 index 00000000000..683358a0e3b --- /dev/null +++ b/tests/cases/compiler/exportSpecifierReferencingOuterDeclaration2.ts @@ -0,0 +1,7 @@ +// @module: commonjs +// @Filename: exportSpecifierReferencingOuterDeclaration2_A.ts +declare module X { export interface bar { } } + +// @Filename: exportSpecifierReferencingOuterDeclaration2_B.ts +export { X }; +export declare function foo(): X.bar; \ No newline at end of file diff --git a/tests/cases/compiler/exportSpecifierReferencingOuterDeclaration3.ts b/tests/cases/compiler/exportSpecifierReferencingOuterDeclaration3.ts new file mode 100644 index 00000000000..d4ddf3cc4a6 --- /dev/null +++ b/tests/cases/compiler/exportSpecifierReferencingOuterDeclaration3.ts @@ -0,0 +1,7 @@ +declare module X { export interface bar { } } +declare module "m" { + module X { export interface foo { } } + export { X }; + export function foo(): X.foo; + export function bar(): X.bar; // error +} \ No newline at end of file diff --git a/tests/cases/compiler/exportSpecifierReferencingOuterDeclaration4.ts b/tests/cases/compiler/exportSpecifierReferencingOuterDeclaration4.ts new file mode 100644 index 00000000000..5beaf1de126 --- /dev/null +++ b/tests/cases/compiler/exportSpecifierReferencingOuterDeclaration4.ts @@ -0,0 +1,9 @@ +// @module: commonjs +// @Filename: exportSpecifierReferencingOuterDeclaration2_A.ts +declare module X { export interface bar { } } + +// @Filename: exportSpecifierReferencingOuterDeclaration2_B.ts +declare module X { export interface foo { } } +export { X }; +export declare function foo(): X.foo; +export declare function bar(): X.bar; // error \ No newline at end of file From 3db5bbf93ffc06afe707a0a9a5cb016b061404a7 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 5 Jun 2015 12:00:53 -0700 Subject: [PATCH 13/13] wrap host.getCanonicalFileName in arrow function --- src/compiler/program.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 5c40230484a..1cfe4d77b6f 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -152,7 +152,7 @@ module ts { let start = new Date().getTime(); host = host || createCompilerHost(options); - let filesByName = createFileMap(host.getCanonicalFileName); + let filesByName = createFileMap(fileName => host.getCanonicalFileName(fileName)); forEach(rootNames, name => processRootFile(name, false)); if (!seenNoDefaultLib) {