ui5-community / babel-plugin-transform-modules-ui5

A Babel transformer plugin for OpenUI5/SAPUI5. It allows you to develop UI5 applications by using the latest ECMAScript or TypeScript, including new syntax and objective oriented programming technology.
MIT License
34 stars 16 forks source link

Compilation error with recent version of Babel parser #52

Closed o0Djeen0o closed 3 years ago

o0Djeen0o commented 3 years ago

Hi,

We recently upgraded babel stack and started to have issues with Typescript integration. Basically, if a file only contains type declarations, like :

export interface IMyInterface {
    id: string;
}

then Babel will type it as an ExportNamedDeclaration

(see this fixture with input and output)

However, from babel plugin transform UI5 side, it seems that such node is not skipped, leading to an error and impossibility to compile :

SyntaxError: C:\<my-interface>.ts: Unknown ExportNamedDeclaration shape. (This is an error on an internal node. Probably an internal error.)
    at File.buildCodeFrameError (C:\<my-project>\node_modules\@babel\core\lib\transformation\file\file.js:244:12)
    at NodePath.buildCodeFrameError (C:\<my-project>\node_modules\@babel\traverse\lib\path\index.js:133:21)
    at PluginPass.ExportNamedDeclaration (C:\<my-project>\node_modules\babel-plugin-transform-modules-ui5\dist\modules\visitor.js:244:18)
    at newFn (C:\<my-project>\node_modules\@babel\traverse\lib\visitors.js:171:21)
    at NodePath._call (C:\<my-project>\node_modules\@babel\traverse\lib\path\context.js:53:20)
    at NodePath.call (C:\<my-project>\node_modules\@babel\traverse\lib\path\context.js:40:17)
    at NodePath.visit (C:\<my-project>\node_modules\@babel\traverse\lib\path\context.js:90:31)
    at TraversalContext.visitQueue (C:\<my-project>\node_modules\@babel\traverse\lib\context.js:110:16)
    at TraversalContext.visitSingle (C:\<my-project>\node_modules\@babel\traverse\lib\context.js:79:19)
    at TraversalContext.visit (C:\<my-project>\node_modules\@babel\traverse\lib\context.js:138:19) {
  code: 'BABEL_TRANSFORM_ERROR'

For me, a quick win would be to skip visiting such node from the plugin. For instance, here we should add a check for the node type, like :

 if (node.type === "ExportNamedDeclaration") {
    return;
  }

Maybe this is a bit to simple and would need some refinements ?

Any help would be welcomed, as I'm not confident with my AST parsing comprehension :-)

Best regards

o0Djeen0o commented 3 years ago

Hi,

The error is related to this change: https://github.com/babel/babel/pull/13314

lemaiwo commented 3 years ago

Facing the same problem, any solution for this?

GuillaumedesPommareSAP commented 3 years ago

Facing the same problem, any solution for this?

I opened a PR for this issue: https://github.com/r-murphy/babel-plugin-transform-modules-ui5/pull/53 Not sure if it will be the final fix, at least it solved the problem in our use case.

r-murphy commented 3 years ago

Thanks for the PR @GuillaumedesPommareSAP. I just published a quick patch release 7.0.4. Please give a try.

I have another branch in progress with some other dependency updates.