How do I tell Babel not to care about what it doesn't understand?

I have a piece of Javascript code with the decorator and import syntax used. I told Babel to transform it per @babel/plugin-transform-modules-commonjs and it complains to me of not giving it the @babel/plugin-proposal-decorators work, when I don't want to transpile anything but “import.”

{ SyntaxError: ……\code.mjs: Support for the experimental syntax 'decorators-legacy' isn't currently enabled (9:2):

……

  pos: 184,
  loc: Position { line: 9, column: 1 },
  missingPlugin: [ 'decorators-legacy', 'decorators' ],
  code: 'BABEL_PARSE_ERROR' }

How do I properly tell

“Just do your @babel/plugin-transform-modules-commonjs job that I gave you and do not ever give a dang about decorator thingies.”

to Babel?

Upvotes: 0

Views: 108

Answers (1)

loganfsmyth
loganfsmyth

Reputation: 161517

All of Babel's experimental syntax transformations come in pairs, one of which enables only parsing, and one of which enables parsing and transformation:

  • @babel/plugin-proposal-decorators
  • @babel/plugin-syntax-decorators

Since you don't want to transform, you'd want to use @babel/plugin-syntax-decorators.

Upvotes: 1

Related Questions