Skip to content

Commit adad7c1

Browse files
committed
Merge pull request #2569 from Microsoft/revertModuleImportFix
revert fix for #2456 'Import namespace exports should be immutable'
2 parents 0245211 + cfda7df commit adad7c1

File tree

4 files changed

+16
-114
lines changed

4 files changed

+16
-114
lines changed

src/compiler/checker.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7387,23 +7387,6 @@ module ts {
73877387
}
73887388
}
73897389

7390-
function isImportedNameFromExternalModule(n: Node): boolean {
7391-
switch (n.kind) {
7392-
case SyntaxKind.ElementAccessExpression:
7393-
case SyntaxKind.PropertyAccessExpression: {
7394-
// all bindings for external module should be immutable
7395-
// so attempt to use a.b or a[b] as lhs will always fail
7396-
// no matter what b is
7397-
let symbol = findSymbol((<PropertyAccessExpression | ElementAccessExpression>n).expression);
7398-
return symbol && symbol.flags & SymbolFlags.Alias && isExternalModuleSymbol(resolveAlias(symbol));
7399-
}
7400-
case SyntaxKind.ParenthesizedExpression:
7401-
return isImportedNameFromExternalModule((<ParenthesizedExpression>n).expression);
7402-
default:
7403-
return false;
7404-
}
7405-
}
7406-
74077390
if (!isReferenceOrErrorExpression(n)) {
74087391
error(n, invalidReferenceMessage);
74097392
return false;
@@ -7414,10 +7397,6 @@ module ts {
74147397
return false;
74157398
}
74167399

7417-
if (isImportedNameFromExternalModule(n)) {
7418-
error(n, invalidReferenceMessage);
7419-
}
7420-
74217400
return true;
74227401
}
74237402

Lines changed: 11 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,164 +1,82 @@
1-
tests/cases/compiler/f2.ts(5,1): error TS2364: Invalid left-hand side of assignment expression.
2-
tests/cases/compiler/f2.ts(6,1): error TS2364: Invalid left-hand side of assignment expression.
3-
tests/cases/compiler/f2.ts(7,1): error TS2364: Invalid left-hand side of assignment expression.
4-
tests/cases/compiler/f2.ts(7,7): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'.
5-
tests/cases/compiler/f2.ts(8,1): error TS2364: Invalid left-hand side of assignment expression.
6-
tests/cases/compiler/f2.ts(10,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer.
7-
tests/cases/compiler/f2.ts(11,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer.
8-
tests/cases/compiler/f2.ts(12,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer.
9-
tests/cases/compiler/f2.ts(13,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer.
10-
tests/cases/compiler/f2.ts(15,1): error TS2364: Invalid left-hand side of assignment expression.
11-
tests/cases/compiler/f2.ts(16,1): error TS2364: Invalid left-hand side of assignment expression.
12-
tests/cases/compiler/f2.ts(17,1): error TS2364: Invalid left-hand side of assignment expression.
13-
tests/cases/compiler/f2.ts(17,8): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'.
14-
tests/cases/compiler/f2.ts(18,1): error TS2364: Invalid left-hand side of assignment expression.
15-
tests/cases/compiler/f2.ts(20,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer.
16-
tests/cases/compiler/f2.ts(21,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer.
17-
tests/cases/compiler/f2.ts(22,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer.
18-
tests/cases/compiler/f2.ts(23,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer.
19-
tests/cases/compiler/f2.ts(25,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'.
20-
tests/cases/compiler/f2.ts(26,6): error TS2487: Invalid left-hand side in 'for...of' statement.
1+
tests/cases/compiler/f2.ts(9,7): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'.
2+
tests/cases/compiler/f2.ts(19,8): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'.
213
tests/cases/compiler/f2.ts(27,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'.
22-
tests/cases/compiler/f2.ts(28,6): error TS2487: Invalid left-hand side in 'for...of' statement.
23-
tests/cases/compiler/f2.ts(29,6): error TS2406: Invalid left-hand side in 'for...in' statement.
24-
tests/cases/compiler/f2.ts(29,12): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'.
25-
tests/cases/compiler/f2.ts(30,6): error TS2487: Invalid left-hand side in 'for...of' statement.
26-
tests/cases/compiler/f2.ts(30,12): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'.
27-
tests/cases/compiler/f2.ts(31,6): error TS2406: Invalid left-hand side in 'for...in' statement.
28-
tests/cases/compiler/f2.ts(32,6): error TS2487: Invalid left-hand side in 'for...of' statement.
29-
tests/cases/compiler/f2.ts(34,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'.
30-
tests/cases/compiler/f2.ts(35,6): error TS2487: Invalid left-hand side in 'for...of' statement.
4+
tests/cases/compiler/f2.ts(29,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'.
5+
tests/cases/compiler/f2.ts(31,12): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'.
6+
tests/cases/compiler/f2.ts(32,12): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'.
317
tests/cases/compiler/f2.ts(36,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'.
32-
tests/cases/compiler/f2.ts(37,6): error TS2487: Invalid left-hand side in 'for...of' statement.
33-
tests/cases/compiler/f2.ts(38,6): error TS2406: Invalid left-hand side in 'for...in' statement.
34-
tests/cases/compiler/f2.ts(38,13): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'.
35-
tests/cases/compiler/f2.ts(39,6): error TS2487: Invalid left-hand side in 'for...of' statement.
36-
tests/cases/compiler/f2.ts(39,13): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'.
37-
tests/cases/compiler/f2.ts(40,6): error TS2406: Invalid left-hand side in 'for...in' statement.
38-
tests/cases/compiler/f2.ts(41,6): error TS2487: Invalid left-hand side in 'for...of' statement.
8+
tests/cases/compiler/f2.ts(38,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'.
9+
tests/cases/compiler/f2.ts(40,13): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'.
10+
tests/cases/compiler/f2.ts(41,13): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'.
3911

4012

4113
==== tests/cases/compiler/f1.ts (0 errors) ====
4214
export var x = 1;
4315

44-
==== tests/cases/compiler/f2.ts (38 errors) ====
16+
==== tests/cases/compiler/f2.ts (10 errors) ====
17+
18+
// all mutations below are illegal and should be fixed
4519
import * as stuff from 'f1';
4620

4721
var n = 'baz';
4822

4923
stuff.x = 0;
50-
~~~~~~~
51-
!!! error TS2364: Invalid left-hand side of assignment expression.
5224
stuff['x'] = 1;
53-
~~~~~~~~~~
54-
!!! error TS2364: Invalid left-hand side of assignment expression.
5525
stuff.blah = 2;
56-
~~~~~~~~~~
57-
!!! error TS2364: Invalid left-hand side of assignment expression.
5826
~~~~
5927
!!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'.
6028
stuff[n] = 3;
61-
~~~~~~~~
62-
!!! error TS2364: Invalid left-hand side of assignment expression.
6329

6430
stuff.x++;
65-
~~~~~~~
66-
!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer.
6731
stuff['x']++;
68-
~~~~~~~~~~
69-
!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer.
7032
stuff['blah']++;
71-
~~~~~~~~~~~~~
72-
!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer.
7333
stuff[n]++;
74-
~~~~~~~~
75-
!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer.
7634

7735
(stuff.x) = 0;
78-
~~~~~~~~~
79-
!!! error TS2364: Invalid left-hand side of assignment expression.
8036
(stuff['x']) = 1;
81-
~~~~~~~~~~~~
82-
!!! error TS2364: Invalid left-hand side of assignment expression.
8337
(stuff.blah) = 2;
84-
~~~~~~~~~~~~
85-
!!! error TS2364: Invalid left-hand side of assignment expression.
8638
~~~~
8739
!!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'.
8840
(stuff[n]) = 3;
89-
~~~~~~~~~~
90-
!!! error TS2364: Invalid left-hand side of assignment expression.
9141

9242
(stuff.x)++;
93-
~~~~~~~~~
94-
!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer.
9543
(stuff['x'])++;
96-
~~~~~~~~~~~~
97-
!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer.
9844
(stuff['blah'])++;
99-
~~~~~~~~~~~~~~~
100-
!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer.
10145
(stuff[n])++;
102-
~~~~~~~~~~
103-
!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer.
10446

10547
for (stuff.x in []) {}
10648
~~~~~~~
10749
!!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'.
10850
for (stuff.x of []) {}
109-
~~~~~~~
110-
!!! error TS2487: Invalid left-hand side in 'for...of' statement.
11151
for (stuff['x'] in []) {}
11252
~~~~~~~~~~
11353
!!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'.
11454
for (stuff['x'] of []) {}
115-
~~~~~~~~~~
116-
!!! error TS2487: Invalid left-hand side in 'for...of' statement.
11755
for (stuff.blah in []) {}
118-
~~~~~~~~~~
119-
!!! error TS2406: Invalid left-hand side in 'for...in' statement.
12056
~~~~
12157
!!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'.
12258
for (stuff.blah of []) {}
123-
~~~~~~~~~~
124-
!!! error TS2487: Invalid left-hand side in 'for...of' statement.
12559
~~~~
12660
!!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'.
12761
for (stuff[n] in []) {}
128-
~~~~~~~~
129-
!!! error TS2406: Invalid left-hand side in 'for...in' statement.
13062
for (stuff[n] of []) {}
131-
~~~~~~~~
132-
!!! error TS2487: Invalid left-hand side in 'for...of' statement.
13363

13464
for ((stuff.x) in []) {}
13565
~~~~~~~~~
13666
!!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'.
13767
for ((stuff.x) of []) {}
138-
~~~~~~~~~
139-
!!! error TS2487: Invalid left-hand side in 'for...of' statement.
14068
for ((stuff['x']) in []) {}
14169
~~~~~~~~~~~~
14270
!!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'.
14371
for ((stuff['x']) of []) {}
144-
~~~~~~~~~~~~
145-
!!! error TS2487: Invalid left-hand side in 'for...of' statement.
14672
for ((stuff.blah) in []) {}
147-
~~~~~~~~~~~~
148-
!!! error TS2406: Invalid left-hand side in 'for...in' statement.
14973
~~~~
15074
!!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'.
15175
for ((stuff.blah) of []) {}
152-
~~~~~~~~~~~~
153-
!!! error TS2487: Invalid left-hand side in 'for...of' statement.
15476
~~~~
15577
!!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'.
15678
for ((stuff[n]) in []) {}
157-
~~~~~~~~~~
158-
!!! error TS2406: Invalid left-hand side in 'for...in' statement.
15979
for ((stuff[n]) of []) {}
160-
~~~~~~~~~~
161-
!!! error TS2487: Invalid left-hand side in 'for...of' statement.
16280

16381

16482

tests/baselines/reference/externalModuleImmutableBindings.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
export var x = 1;
55

66
//// [f2.ts]
7+
8+
// all mutations below are illegal and should be fixed
79
import * as stuff from 'f1';
810

911
var n = 'baz';
@@ -52,6 +54,7 @@ for ((stuff[n]) of []) {}
5254
//// [f1.js]
5355
exports.x = 1;
5456
//// [f2.js]
57+
// all mutations below are illegal and should be fixed
5558
var stuff = require('f1');
5659
var n = 'baz';
5760
stuff.x = 0;

tests/cases/compiler/externalModuleImmutableBindings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
export var x = 1;
44

55
// @Filename: f2.ts
6+
7+
// all mutations below are illegal and should be fixed
68
import * as stuff from 'f1';
79

810
var n = 'baz';

0 commit comments

Comments
 (0)