-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disallow assignments to imported exports #2476
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
tests/baselines/reference/externalModuleImmutableBindings.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
tests/cases/compiler/f2.ts(5,1): error TS2364: Invalid left-hand side of assignment expression. | ||
tests/cases/compiler/f2.ts(6,1): error TS2364: Invalid left-hand side of assignment expression. | ||
tests/cases/compiler/f2.ts(7,1): error TS2364: Invalid left-hand side of assignment expression. | ||
tests/cases/compiler/f2.ts(7,7): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. | ||
tests/cases/compiler/f2.ts(8,1): error TS2364: Invalid left-hand side of assignment expression. | ||
tests/cases/compiler/f2.ts(10,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. | ||
tests/cases/compiler/f2.ts(11,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. | ||
tests/cases/compiler/f2.ts(12,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. | ||
tests/cases/compiler/f2.ts(13,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. | ||
tests/cases/compiler/f2.ts(15,1): error TS2364: Invalid left-hand side of assignment expression. | ||
tests/cases/compiler/f2.ts(16,1): error TS2364: Invalid left-hand side of assignment expression. | ||
tests/cases/compiler/f2.ts(17,1): error TS2364: Invalid left-hand side of assignment expression. | ||
tests/cases/compiler/f2.ts(17,8): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. | ||
tests/cases/compiler/f2.ts(18,1): error TS2364: Invalid left-hand side of assignment expression. | ||
tests/cases/compiler/f2.ts(20,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. | ||
tests/cases/compiler/f2.ts(21,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. | ||
tests/cases/compiler/f2.ts(22,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. | ||
tests/cases/compiler/f2.ts(23,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. | ||
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'. | ||
tests/cases/compiler/f2.ts(26,6): error TS2487: Invalid left-hand side in 'for...of' statement. | ||
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'. | ||
tests/cases/compiler/f2.ts(28,6): error TS2487: Invalid left-hand side in 'for...of' statement. | ||
tests/cases/compiler/f2.ts(29,6): error TS2406: Invalid left-hand side in 'for...in' statement. | ||
tests/cases/compiler/f2.ts(29,12): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. | ||
tests/cases/compiler/f2.ts(30,6): error TS2487: Invalid left-hand side in 'for...of' statement. | ||
tests/cases/compiler/f2.ts(30,12): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. | ||
tests/cases/compiler/f2.ts(31,6): error TS2406: Invalid left-hand side in 'for...in' statement. | ||
tests/cases/compiler/f2.ts(32,6): error TS2487: Invalid left-hand side in 'for...of' statement. | ||
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'. | ||
tests/cases/compiler/f2.ts(35,6): error TS2487: Invalid left-hand side in 'for...of' statement. | ||
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'. | ||
tests/cases/compiler/f2.ts(37,6): error TS2487: Invalid left-hand side in 'for...of' statement. | ||
tests/cases/compiler/f2.ts(38,6): error TS2406: Invalid left-hand side in 'for...in' statement. | ||
tests/cases/compiler/f2.ts(38,13): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. | ||
tests/cases/compiler/f2.ts(39,6): error TS2487: Invalid left-hand side in 'for...of' statement. | ||
tests/cases/compiler/f2.ts(39,13): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. | ||
tests/cases/compiler/f2.ts(40,6): error TS2406: Invalid left-hand side in 'for...in' statement. | ||
tests/cases/compiler/f2.ts(41,6): error TS2487: Invalid left-hand side in 'for...of' statement. | ||
|
||
|
||
==== tests/cases/compiler/f1.ts (0 errors) ==== | ||
export var x = 1; | ||
|
||
==== tests/cases/compiler/f2.ts (38 errors) ==== | ||
import * as stuff from 'f1'; | ||
|
||
var n = 'baz'; | ||
|
||
stuff.x = 0; | ||
~~~~~~~ | ||
!!! error TS2364: Invalid left-hand side of assignment expression. | ||
stuff['x'] = 1; | ||
~~~~~~~~~~ | ||
!!! error TS2364: Invalid left-hand side of assignment expression. | ||
stuff.blah = 2; | ||
~~~~~~~~~~ | ||
!!! error TS2364: Invalid left-hand side of assignment expression. | ||
~~~~ | ||
!!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. | ||
stuff[n] = 3; | ||
~~~~~~~~ | ||
!!! error TS2364: Invalid left-hand side of assignment expression. | ||
|
||
stuff.x++; | ||
~~~~~~~ | ||
!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. | ||
stuff['x']++; | ||
~~~~~~~~~~ | ||
!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. | ||
stuff['blah']++; | ||
~~~~~~~~~~~~~ | ||
!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. | ||
stuff[n]++; | ||
~~~~~~~~ | ||
!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. | ||
|
||
(stuff.x) = 0; | ||
~~~~~~~~~ | ||
!!! error TS2364: Invalid left-hand side of assignment expression. | ||
(stuff['x']) = 1; | ||
~~~~~~~~~~~~ | ||
!!! error TS2364: Invalid left-hand side of assignment expression. | ||
(stuff.blah) = 2; | ||
~~~~~~~~~~~~ | ||
!!! error TS2364: Invalid left-hand side of assignment expression. | ||
~~~~ | ||
!!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. | ||
(stuff[n]) = 3; | ||
~~~~~~~~~~ | ||
!!! error TS2364: Invalid left-hand side of assignment expression. | ||
|
||
(stuff.x)++; | ||
~~~~~~~~~ | ||
!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. | ||
(stuff['x'])++; | ||
~~~~~~~~~~~~ | ||
!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. | ||
(stuff['blah'])++; | ||
~~~~~~~~~~~~~~~ | ||
!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. | ||
(stuff[n])++; | ||
~~~~~~~~~~ | ||
!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. | ||
|
||
for (stuff.x in []) {} | ||
~~~~~~~ | ||
!!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. | ||
for (stuff.x of []) {} | ||
~~~~~~~ | ||
!!! error TS2487: Invalid left-hand side in 'for...of' statement. | ||
for (stuff['x'] in []) {} | ||
~~~~~~~~~~ | ||
!!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. | ||
for (stuff['x'] of []) {} | ||
~~~~~~~~~~ | ||
!!! error TS2487: Invalid left-hand side in 'for...of' statement. | ||
for (stuff.blah in []) {} | ||
~~~~~~~~~~ | ||
!!! error TS2406: Invalid left-hand side in 'for...in' statement. | ||
~~~~ | ||
!!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. | ||
for (stuff.blah of []) {} | ||
~~~~~~~~~~ | ||
!!! error TS2487: Invalid left-hand side in 'for...of' statement. | ||
~~~~ | ||
!!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. | ||
for (stuff[n] in []) {} | ||
~~~~~~~~ | ||
!!! error TS2406: Invalid left-hand side in 'for...in' statement. | ||
for (stuff[n] of []) {} | ||
~~~~~~~~ | ||
!!! error TS2487: Invalid left-hand side in 'for...of' statement. | ||
|
||
for ((stuff.x) in []) {} | ||
~~~~~~~~~ | ||
!!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. | ||
for ((stuff.x) of []) {} | ||
~~~~~~~~~ | ||
!!! error TS2487: Invalid left-hand side in 'for...of' statement. | ||
for ((stuff['x']) in []) {} | ||
~~~~~~~~~~~~ | ||
!!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. | ||
for ((stuff['x']) of []) {} | ||
~~~~~~~~~~~~ | ||
!!! error TS2487: Invalid left-hand side in 'for...of' statement. | ||
for ((stuff.blah) in []) {} | ||
~~~~~~~~~~~~ | ||
!!! error TS2406: Invalid left-hand side in 'for...in' statement. | ||
~~~~ | ||
!!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. | ||
for ((stuff.blah) of []) {} | ||
~~~~~~~~~~~~ | ||
!!! error TS2487: Invalid left-hand side in 'for...of' statement. | ||
~~~~ | ||
!!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. | ||
for ((stuff[n]) in []) {} | ||
~~~~~~~~~~ | ||
!!! error TS2406: Invalid left-hand side in 'for...in' statement. | ||
for ((stuff[n]) of []) {} | ||
~~~~~~~~~~ | ||
!!! error TS2487: Invalid left-hand side in 'for...of' statement. | ||
|
||
|
||
|
112 changes: 112 additions & 0 deletions
112
tests/baselines/reference/externalModuleImmutableBindings.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
//// [tests/cases/compiler/externalModuleImmutableBindings.ts] //// | ||
|
||
//// [f1.ts] | ||
export var x = 1; | ||
|
||
//// [f2.ts] | ||
import * as stuff from 'f1'; | ||
|
||
var n = 'baz'; | ||
|
||
stuff.x = 0; | ||
stuff['x'] = 1; | ||
stuff.blah = 2; | ||
stuff[n] = 3; | ||
|
||
stuff.x++; | ||
stuff['x']++; | ||
stuff['blah']++; | ||
stuff[n]++; | ||
|
||
(stuff.x) = 0; | ||
(stuff['x']) = 1; | ||
(stuff.blah) = 2; | ||
(stuff[n]) = 3; | ||
|
||
(stuff.x)++; | ||
(stuff['x'])++; | ||
(stuff['blah'])++; | ||
(stuff[n])++; | ||
|
||
for (stuff.x in []) {} | ||
for (stuff.x of []) {} | ||
for (stuff['x'] in []) {} | ||
for (stuff['x'] of []) {} | ||
for (stuff.blah in []) {} | ||
for (stuff.blah of []) {} | ||
for (stuff[n] in []) {} | ||
for (stuff[n] of []) {} | ||
|
||
for ((stuff.x) in []) {} | ||
for ((stuff.x) of []) {} | ||
for ((stuff['x']) in []) {} | ||
for ((stuff['x']) of []) {} | ||
for ((stuff.blah) in []) {} | ||
for ((stuff.blah) of []) {} | ||
for ((stuff[n]) in []) {} | ||
for ((stuff[n]) of []) {} | ||
|
||
|
||
|
||
|
||
//// [f1.js] | ||
exports.x = 1; | ||
//// [f2.js] | ||
var stuff = require('f1'); | ||
var n = 'baz'; | ||
stuff.x = 0; | ||
stuff['x'] = 1; | ||
stuff.blah = 2; | ||
stuff[n] = 3; | ||
stuff.x++; | ||
stuff['x']++; | ||
stuff['blah']++; | ||
stuff[n]++; | ||
(stuff.x) = 0; | ||
(stuff['x']) = 1; | ||
(stuff.blah) = 2; | ||
(stuff[n]) = 3; | ||
(stuff.x)++; | ||
(stuff['x'])++; | ||
(stuff['blah'])++; | ||
(stuff[n])++; | ||
for (stuff.x in []) { | ||
} | ||
for (var _i = 0, _a = []; _i < _a.length; _i++) { | ||
stuff.x = _a[_i]; | ||
} | ||
for (stuff['x'] in []) { | ||
} | ||
for (var _b = 0, _c = []; _b < _c.length; _b++) { | ||
stuff['x'] = _c[_b]; | ||
} | ||
for (stuff.blah in []) { | ||
} | ||
for (var _d = 0, _e = []; _d < _e.length; _d++) { | ||
stuff.blah = _e[_d]; | ||
} | ||
for (stuff[n] in []) { | ||
} | ||
for (var _f = 0, _g = []; _f < _g.length; _f++) { | ||
stuff[n] = _g[_f]; | ||
} | ||
for ((stuff.x) in []) { | ||
} | ||
for (var _h = 0, _j = []; _h < _j.length; _h++) { | ||
(stuff.x) = _j[_h]; | ||
} | ||
for ((stuff['x']) in []) { | ||
} | ||
for (var _k = 0, _l = []; _k < _l.length; _k++) { | ||
(stuff['x']) = _l[_k]; | ||
} | ||
for ((stuff.blah) in []) { | ||
} | ||
for (var _m = 0, _o = []; _m < _o.length; _m++) { | ||
(stuff.blah) = _o[_m]; | ||
} | ||
for ((stuff[n]) in []) { | ||
} | ||
for (var _p = 0, _q = []; _p < _q.length; _p++) { | ||
(stuff[n]) = _q[_p]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// @module: commonjs | ||
// @Filename: f1.ts | ||
export var x = 1; | ||
|
||
// @Filename: f2.ts | ||
import * as stuff from 'f1'; | ||
|
||
var n = 'baz'; | ||
|
||
stuff.x = 0; | ||
stuff['x'] = 1; | ||
stuff.blah = 2; | ||
stuff[n] = 3; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
stuff.x++; | ||
stuff['x']++; | ||
stuff['blah']++; | ||
stuff[n]++; | ||
|
||
(stuff.x) = 0; | ||
(stuff['x']) = 1; | ||
(stuff.blah) = 2; | ||
(stuff[n]) = 3; | ||
|
||
(stuff.x)++; | ||
(stuff['x'])++; | ||
(stuff['blah'])++; | ||
(stuff[n])++; | ||
|
||
for (stuff.x in []) {} | ||
for (stuff.x of []) {} | ||
for (stuff['x'] in []) {} | ||
for (stuff['x'] of []) {} | ||
for (stuff.blah in []) {} | ||
for (stuff.blah of []) {} | ||
for (stuff[n] in []) {} | ||
for (stuff[n] of []) {} | ||
|
||
for ((stuff.x) in []) {} | ||
for ((stuff.x) of []) {} | ||
for ((stuff['x']) in []) {} | ||
for ((stuff['x']) of []) {} | ||
for ((stuff.blah) in []) {} | ||
for ((stuff.blah) of []) {} | ||
for ((stuff[n]) in []) {} | ||
for ((stuff[n]) of []) {} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already an inner function so it should be able to refer to the node from the outer function. Why you have to pass it in as function argument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is both the question of style (use explicit inputs\outputs for function) and potential optimization opportunities (in theory nested function that does not any captured data can be lifted to a higher scope)