3

I am trying to transpile a set of js files.As babel by default operates in a strict mode,it outputs a syntax error whenever there is a conflict for example use of a delete keyword.The solution I am looking for is to somehow ignore this strict mode. Please note that I am doing above operation using babel cli and that there is no project set-up.

Edit: I am aware of how delete works in strict mode.The question is to use babel to operate in non-strict mode so that it won't give errors as by default it parses files as ES6 modules.

babel delete keyword conflict in strict mode

Shashank Singh
  • 163
  • 4
  • 11
  • Possible duplicate of [Why is delete not allowed in Javascript5 strict mode?](https://stackoverflow.com/questions/16652589/why-is-delete-not-allowed-in-javascript5-strict-mode) – Dom Aug 31 '18 at 08:18

1 Answers1

1

I have figured out the solution.By default Babel parses the files as ES6 modules, which are strict by default.If we add the --source-type script in case one is using cli,then it will work.I am writing a simple command to transpile a single js file which will ignore strict mode,in case someone gets stuck on this in future.One key note is you need to upgrade to latest babel 7 to make it work.

babel test.js --presets=@babel/env --source-type script --out-file test_new.js
Shashank Singh
  • 163
  • 4
  • 11