Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transform commonjs: show warning on import/export of reserved keyword #313

Open
milahu opened this issue Sep 15, 2020 · 1 comment
Open
Labels

Comments

@milahu
Copy link

milahu commented Sep 15, 2020

this works in es5

exports.new = function() {};

this fails in es6

export function new() {}

cos new is a reserved keyword

only solution is to rename the export/import
lebab should at least show a warning

@frank-dspeed
Copy link

This is a nice One! i will write about that in my book thanks for supplying this but let me show you a importent code style change when you code esModules

exports.new = function() {}; // Wrong Really bad!
'use strict' // Only needed in the first file but is here for education
const new = function() {}; // This already errors even in es5
exports.new = new; // Good thing we assign to exports a already defined var
Welcome to Node.js v17.1.0.
Type ".help" for more information.
> const new = ''
const new = ''
      ^^^

Uncaught SyntaxError: Unexpected token 'new'
> 

this error is also already correctly catched by eslint and typescript so this can be closed its out of scope for lebab to run such checks before the main transform applys while i think it would be nice to add something that changes

exports.new = function() {};

to

const new = function() {}; 
exports.new = new;

and use that as pre transform so that people could check if that cjs code runs before they apply the import/export transform

@nene nene added the bug label Mar 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants