Packages: Invalid scope in JS export statement

Created on 15 Nov 2017  路  4Comments  路  Source: sublimehq/Packages

Using dev build of Sublime (3153)

Scope of some code in built-in JS implementation

image

Same file and location with the Babel package:

image

Most helpful comment

This behavior is correct. The export default form requires a trailing semicolon. In this example, there is no semicolon, so the syntax will assume that the exported expression continues until it reaches either a semicolon, an unexpected character, or a lookahead indicating that the automatic semicolon insertion algorithm would add a semicolon. A related example:

export default {
    foo: 42
}
/* some comment */
['foo'];

This will export 42. The line ['foo'] is not an array literal, but a property access. See this comment for more details.

Previous versions of the JavaScript syntax handled this incorrectly, resulting in a number of bugs. PR #1009 restructured the syntax definition so that it would systematically do the right thing in these sorts of cases. Unfortunately, the Vue syntax assumes that when the closing </script> tag is encountered, the JavaScript syntax will only have the main scope on the stack. The Vue syntax will have to be modified to handle embedded JavaScript correctly.

All 4 comments

1302 probably related and relevant.

This behavior is correct. The export default form requires a trailing semicolon. In this example, there is no semicolon, so the syntax will assume that the exported expression continues until it reaches either a semicolon, an unexpected character, or a lookahead indicating that the automatic semicolon insertion algorithm would add a semicolon. A related example:

export default {
    foo: 42
}
/* some comment */
['foo'];

This will export 42. The line ['foo'] is not an array literal, but a property access. See this comment for more details.

Previous versions of the JavaScript syntax handled this incorrectly, resulting in a number of bugs. PR #1009 restructured the syntax definition so that it would systematically do the right thing in these sorts of cases. Unfortunately, the Vue syntax assumes that when the closing </script> tag is encountered, the JavaScript syntax will only have the main scope on the stack. The Vue syntax will have to be modified to handle embedded JavaScript correctly.

@skyronic Since we've sorted out the Vue stuff, can this issue be closed?

This appears to be resolved now

Was this page helpful?
0 / 5 - 0 ratings