skip 'import ...' nodes when creating variable statement for imports

This commit is contained in:
Vladimir Matveev 2015-04-20 14:17:38 -07:00
parent dcb4c24b43
commit 6e5082658d
15 changed files with 193 additions and 26 deletions

View File

@ -4880,7 +4880,11 @@ var __param = this.__param || function(index, decorator) { return function (targ
writeLine();
let started = false;
for (let importNode of externalImports) {
if (importNode.kind === SyntaxKind.ExportDeclaration) {
let skipNode =
importNode.kind === SyntaxKind.ExportDeclaration ||
(importNode.kind === SyntaxKind.ImportDeclaration && !(<ImportDeclaration>importNode).importClause)
if (skipNode) {
continue;
}

View File

@ -16,8 +16,8 @@ System.register(['file1', 'file2'], function(exports_1) {
setters:[
function (v_1) {
file1_1 = v_1
exports_1("n", file1_1.default);
exports_1("n1", file1_1.default);
exports_1("n", file1_1["default"]);
exports_1("n1", file1_1["default"]);
exports_1("x", file1_1.x);
exports_1("y", file1_1.x);
},

View File

@ -0,0 +1,11 @@
tests/cases/compiler/systemModule11.ts(3,17): error TS2307: Cannot find external module 'bar'.
==== tests/cases/compiler/systemModule11.ts (1 errors) ====
import 'foo'
import {f} from 'bar';
~~~~~
!!! error TS2307: Cannot find external module 'bar'.
f();

View File

@ -0,0 +1,21 @@
//// [systemModule11.ts]
import 'foo'
import {f} from 'bar';
f();
//// [systemModule11.js]
System.register(['foo', 'bar'], function(exports_1) {
var bar_1;
return {
setters:[
function (v_1) {},
function (v_1) {
bar_1 = v_1
}],
execute: function() {
bar_1.f();
}
}
});

View File

@ -1,4 +1,4 @@
tests/cases/compiler/systemModule2.ts(3,1): error TS1212: Export assignment is not supported when '--module' flag is 'system'.
tests/cases/compiler/systemModule2.ts(3,1): error TS1218: Export assignment is not supported when '--module' flag is 'system'.
==== tests/cases/compiler/systemModule2.ts (1 errors) ====
@ -6,4 +6,4 @@ tests/cases/compiler/systemModule2.ts(3,1): error TS1212: Export assignment is n
var x = 1;
export = x;
~~~~~~~~~~~
!!! error TS1212: Export assignment is not supported when '--module' flag is 'system'.
!!! error TS1218: Export assignment is not supported when '--module' flag is 'system'.

View File

@ -0,0 +1,8 @@
=== tests/cases/compiler/systemModule4.ts ===
export var x = 1;
>x : Symbol(x, Decl(systemModule4.ts, 1, 10))
export var y;
>y : Symbol(y, Decl(systemModule4.ts, 2, 10))

View File

@ -2,6 +2,7 @@
export var x = 1;
>x : number
>1 : number
export var y;
>y : any

View File

@ -0,0 +1,17 @@
=== tests/cases/compiler/systemModule7.ts ===
// filename: instantiatedModule.ts
export module M {
>M : Symbol(M, Decl(systemModule7.ts, 0, 0), Decl(systemModule7.ts, 4, 1))
var x = 1;
>x : Symbol(x, Decl(systemModule7.ts, 3, 7))
}
// filename: nonInstantiatedModule.ts
export module M {
>M : Symbol(M, Decl(systemModule7.ts, 0, 0), Decl(systemModule7.ts, 4, 1))
interface I {}
>I : Symbol(I, Decl(systemModule7.ts, 7, 17))
}

View File

@ -6,6 +6,7 @@ export module M {
var x = 1;
>x : number
>1 : number
}
// filename: nonInstantiatedModule.ts

View File

@ -52,7 +52,7 @@ System.register([], function(exports_1) {
for (exports_1("x", x = 15);; exports_1("x", ++x)) { }
for (exports_1("x", x = 18);; exports_1("x", --x)) { }
for (x_1 = 50;;) { }
exports_1("y", y = ([1])[0]);
exports_1("y", y = [1][0]);
_a = { a: true, b: { c: "123" } }, exports_1("z0", z0 = _a.a), exports_1("z1", z1 = _a.b.c);
for (var _i = 0, _b = [[1]]; _i < _b.length; _i++) {
exports_1("x", x = _b[_i][0]);

View File

@ -0,0 +1,77 @@
=== tests/cases/compiler/systemModule8.ts ===
export var x;
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
x = 1;
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
x++;
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
x--;
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
++x;
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
--x;
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
x += 1;
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
x -= 1;
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
x *= 1;
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
x /= 1;
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
x |= 1;
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
x &= 1;
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
for (x = 5;;x++) {}
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
for (x = 8;;x--) {}
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
for (x = 15;;++x) {}
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
for (x = 18;;--x) {}
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
for (let x = 50;;) {}
>x : Symbol(x, Decl(systemModule8.ts, 18, 8))
function foo() {
>foo : Symbol(foo, Decl(systemModule8.ts, 18, 21))
x = 100;
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
}
export let [y] = [1];
>y : Symbol(y, Decl(systemModule8.ts, 23, 12))
export const {a: z0, b: {c: z1}} = {a: true, b: {c: "123"}};
>z0 : Symbol(z0, Decl(systemModule8.ts, 24, 14))
>z1 : Symbol(z1, Decl(systemModule8.ts, 24, 25))
>a : Symbol(a, Decl(systemModule8.ts, 24, 36))
>b : Symbol(b, Decl(systemModule8.ts, 24, 44))
>c : Symbol(c, Decl(systemModule8.ts, 24, 49))
for ([x] of [[1]]) {}
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))

View File

@ -6,6 +6,7 @@ export var x;
x = 1;
>x = 1 : number
>x : any
>1 : number
x++;
>x++ : number
@ -26,53 +27,64 @@ x--;
x += 1;
>x += 1 : any
>x : any
>1 : number
x -= 1;
>x -= 1 : number
>x : any
>1 : number
x *= 1;
>x *= 1 : number
>x : any
>1 : number
x /= 1;
>x /= 1 : number
>x : any
>1 : number
x |= 1;
>x |= 1 : number
>x : any
>1 : number
x &= 1;
>x &= 1 : number
>x : any
>1 : number
for (x = 5;;x++) {}
>x = 5 : number
>x : any
>5 : number
>x++ : number
>x : any
for (x = 8;;x--) {}
>x = 8 : number
>x : any
>8 : number
>x-- : number
>x : any
for (x = 15;;++x) {}
>x = 15 : number
>x : any
>15 : number
>++x : number
>x : any
for (x = 18;;--x) {}
>x = 18 : number
>x : any
>18 : number
>--x : number
>x : any
for (let x = 50;;) {}
>x : number
>50 : number
function foo() {
>foo : () => void
@ -80,27 +92,32 @@ function foo() {
x = 100;
>x = 100 : number
>x : any
>100 : number
}
export let [y] = [1];
>y : number
>[1] : [number]
>1 : number
export const {a: z0, b: {c: z1}} = {a: true, b: {c: "123"}};
>a : unknown
>a : any
>z0 : boolean
>b : unknown
>c : unknown
>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] : any[]
>x : any
>[[1]] : number[][]
>[1] : number[]
>1 : number

View File

@ -1,9 +1,9 @@
tests/cases/compiler/systemModule9.ts(2,21): error TS2307: Cannot find external module 'file1'.
tests/cases/compiler/systemModule9.ts(3,25): error TS2307: Cannot find external module 'file2'.
tests/cases/compiler/systemModule9.ts(4,15): error TS2307: Cannot find external module 'file3'.
tests/cases/compiler/systemModule9.ts(5,25): error TS2307: Cannot find external module 'file4'.
tests/cases/compiler/systemModule9.ts(6,22): error TS2307: Cannot find external module 'file5'.
tests/cases/compiler/systemModule9.ts(16,15): error TS2307: Cannot find external module 'file6'.
tests/cases/compiler/systemModule9.ts(6,25): error TS2307: Cannot find external module 'file5'.
tests/cases/compiler/systemModule9.ts(7,22): error TS2307: Cannot find external module 'file6'.
tests/cases/compiler/systemModule9.ts(17,15): error TS2307: Cannot find external module 'file7'.
==== tests/cases/compiler/systemModule9.ts (6 errors) ====
@ -17,12 +17,13 @@ tests/cases/compiler/systemModule9.ts(16,15): error TS2307: Cannot find external
import d from 'file3'
~~~~~~~
!!! error TS2307: Cannot find external module 'file3'.
import e, * as ns2 from 'file4';
import 'file4'
import e, * as ns2 from 'file5';
~~~~~~~
!!! error TS2307: Cannot find external module 'file4'.
import ns3 = require('file5');
~~~~~~~
!!! error TS2307: Cannot find external module 'file5'.
import ns3 = require('file6');
~~~~~~~
!!! error TS2307: Cannot find external module 'file6'.
ns.f();
a();
@ -32,9 +33,9 @@ tests/cases/compiler/systemModule9.ts(16,15): error TS2307: Cannot find external
ns2.f();
ns3.f();
export * from 'file6';
export * from 'file7';
~~~~~~~
!!! error TS2307: Cannot find external module 'file6'.
!!! error TS2307: Cannot find external module 'file7'.
var x, y = true;
export {x};

View File

@ -3,8 +3,9 @@
import * as ns from 'file1';
import {a, b as c} from 'file2';
import d from 'file3'
import e, * as ns2 from 'file4';
import ns3 = require('file5');
import 'file4'
import e, * as ns2 from 'file5';
import ns3 = require('file6');
ns.f();
a();
@ -14,15 +15,15 @@ e();
ns2.f();
ns3.f();
export * from 'file6';
export * from 'file7';
var x, y = true;
export {x};
export {y as z};
//// [systemModule9.js]
System.register(['file1', 'file2', 'file3', 'file4', 'file5', 'file6'], function(exports_1) {
var ns, file2_1, file3_1, file4_1, ns3;
System.register(['file1', 'file2', 'file3', 'file4', 'file5', 'file6', 'file7'], function(exports_1) {
var ns, file2_1, file3_1, file5_1, ns3;
var x, y;
return {
setters:[
@ -35,8 +36,9 @@ System.register(['file1', 'file2', 'file3', 'file4', 'file5', 'file6'], function
function (v_1) {
file3_1 = v_1
},
function (v_1) {},
function (v_1) {
file4_1 = v_1
file5_1 = v_1
},
function (v_1) {
ns3 = v_1
@ -48,8 +50,8 @@ System.register(['file1', 'file2', 'file3', 'file4', 'file5', 'file6'], function
ns.f();
file2_1.a();
file2_1.b();
file3_1.default();
file4_1.default();
file3_1["default"]();
file5_1["default"]();
ns2.f();
ns3.f();
y = true;

View File

@ -0,0 +1,7 @@
// @module: system
// @separateCompilation: true
import 'foo'
import {f} from 'bar';
f();