Heya. I've been tinkering around with reactify and ES6 for a little while now, and have been blocked by the errors: Illegal export declaration while parsing file and Illegal import declaration while parsing file.
After some digging, I found that React's JSX Transformer, used by react-tools, does not appear to parse import or export declarations unless you explicitly set a certain flag. Not the harmony flag. For some reason, this flag is currently undocumented. The important flag here is es6module, and it can be found being used in React's JSXTransformer. https://github.com/facebook/react/blob/master/docs/js/JSXTransformer.js
var isModule = extra.sourceType === 'module' || extra.sourceType === 'nonStrictModule';
if (isModule && lookahead.type === Token.Keyword) {
switch (lookahead.value) {
case 'export':
return parseExportDeclaration();
case 'import':
return parseImportDeclaration();
}
}
While I'm still looking into the code, and may not be fully aware of all the implications of this flag, it does appear that, without this flag (or nonStrictEs6Module), it will not parse import or export declarations, leading to the troublesome error I've been getting.
Right now, I've set the es6module flag to be turned on manually in reactify, though an official configuration for this would be appreciated. Cheers!
Heya. I've been tinkering around with reactify and ES6 for a little while now, and have been blocked by the errors:
Illegal export declaration while parsing file
andIllegal import declaration while parsing file
.After some digging, I found that React's JSX Transformer, used by react-tools, does not appear to parse import or export declarations unless you explicitly set a certain flag. Not the harmony flag. For some reason, this flag is currently undocumented. The important flag here is
es6module
, and it can be found being used in React's JSXTransformer. https://github.com/facebook/react/blob/master/docs/js/JSXTransformer.jsSpecifically, take a look at line #8746: https://github.com/facebook/react/blob/master/docs/js/JSXTransformer.js#L8746
While I'm still looking into the code, and may not be fully aware of all the implications of this flag, it does appear that, without this flag (or
nonStrictEs6Module
), it will not parse import or export declarations, leading to the troublesome error I've been getting.Right now, I've set the es6module flag to be turned on manually in reactify, though an official configuration for this would be appreciated. Cheers!