sweet-js / sweet-core

Sweeten your JavaScript.
https://www.sweetjs.org
BSD 2-Clause "Simplified" License
4.59k stars 211 forks source link

Fix missing export in compiled output #719

Closed disnet closed 7 years ago

disnet commented 7 years ago

Export declarations were not being included in the compiled output due to a too aggressive approach to preparing modules for eval inside of sweet. The PR fixes that in a hacky way, the module handling stuff needs a rewrite.

Don't merge this just yet, I want to add a snapshot test as in #718 but need to figure out why travis is complaining first.

michaelficarra commented 7 years ago

@disnet The tests are failing with this error:

run-test262 - 413.module.js:
export { default } from "a"

  /home/travis/build/sweet-js/sweet-core/node_modules/shift-codegen/dist/token_stream.js:95

  Error: tokenStr.charAt is not a function

  TokenStream.put (node_modules/shift-codegen/dist/token_stream.js:95:32)
  Token.emit (node_modules/shift-codegen/dist/coderep.js:247:10)
  Seq.emit (node_modules/shift-codegen/dist/coderep.js:443:21)
  Brace.emit (node_modules/shift-codegen/dist/coderep.js:352:17)
  Seq.emit (node_modules/shift-codegen/dist/coderep.js:443:21)
  Seq.emit (node_modules/shift-codegen/dist/coderep.js:443:21)
  codeGen (node_modules/shift-codegen/dist/index.js:153:7)
  codegen (src/codegen.js:5:11)
  SweetModule.codegen (src/sweet-module.js:184:12)
  compile (src/sweet.js:42:60)
  Test.f (test/parser/test-run-test262.js:671:18)
gabejohnson commented 7 years ago

Yeah it looks like it's the export {...} from ... syntax.

gabejohnson commented 7 years ago

ExportFrom terms aren't being expanded in https://github.com/sweet-js/sweet-core/blob/2160cba80a2b0d3c1cf1b3ae87f40cbf9793cd2b/src/term-expander.js#L402-L404

disnet commented 7 years ago

Thanks for helping track that down. It actually needed to be fixed in the sweet-to-shift-reducer. term-expander is only for forms that have deferred expansion in their bodies (like functions).

disnet commented 7 years ago

Added some tests so this should be good to go.

michaelficarra commented 7 years ago

@disnet Can you create a new release so I can try this out?

disnet commented 7 years ago

@michaelficarra 3.0.9 is now published