Skip to content

Commit eac8a63

Browse files
committed
Expand sourceType explanation
1 parent 545aeb8 commit eac8a63

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

lib/coffeescript/nodes.js

Lines changed: 12 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nodes.coffee

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -796,9 +796,18 @@ exports.Block = class Block extends Base
796796

797797
astProperties: ->
798798
return
799-
# For now, we are not including `sourceType` on the `Program` AST node,
800-
# as we'd like to have a reliable way to determine its proper value and
801-
# things like the ongoing Node modules discussion make that unclear.
799+
# For now, we’re not including `sourceType` on the `Program` AST node.
800+
# Its value could be either `'script'` or `'module'`, and there’s no way
801+
# for CoffeeScript to always know which it should be. The presence of an
802+
# `import` or `export` statement in source code would imply that it should
803+
# be a `module`, but a project may consist of mostly such files and also
804+
# an outlier file that lacks `import` or `export` but is still imported
805+
# into the project and therefore expects to be treated as a `module`.
806+
# Determining the value of `sourceType` is essentially the same challenge
807+
# posed by determining the parse goal of a JavaScript file, also `module`
808+
# or `script`, and so if Node figures out a way to do so for `.js` files
809+
# then CoffeeScript can copy Node’s algorithm.
810+
802811
# sourceType: 'module'
803812
body: @bodyToAst()
804813
directives: []

0 commit comments

Comments
 (0)