Coder Social home page Coder Social logo

Comments (4)

evanw avatar evanw commented on June 9, 2024 1

Wait, maybe it doesn't have anything to do with keywords. It looks like mapping to null works but mapping to 0 doesn't? Here are some tests with various expressions:

module.exports = {fi, if: 0}
{ exports: [ 'fi' ], reexports: [] }

module.exports = {fi, if: !0}
{ exports: [ 'fi' ], reexports: [] }

module.exports = {fi, if: -0}
{ exports: [ 'fi' ], reexports: [] }

module.exports = {fi, if: (true)}
{ exports: [ 'fi' ], reexports: [] }

module.exports = {fi, if: [true]}
{ exports: [ 'fi' ], reexports: [] }

module.exports = {fi, if: null}
{ exports: [ 'fi', 'if' ], reexports: [] }

module.exports = {fi, if: true}
{ exports: [ 'fi', 'if' ], reexports: [] }

I guess this is because the grammar is specified as (IDENTIFIER (`:` IDENTIFIER )?). Is there any reason to not support arbitrary expressions? Like module.exports = { version: '0.1.0' }.

I will use if: null for now.

from cjs-module-lexer.

guybedford avatar guybedford commented on June 9, 2024

@evanw this is just a very simple lexer designed to be small and fast and it doesn't even have an expression parser. We could extend the grammar to support direct primitives in the object form, but for now I'm concerned that may be even more confusing too, it's not a clear line by any means yes. See also #6.

Supporting numbers and strings would be straightforward, I'm just not sure we want to push the blurry line in that direction here, would value your thoughts.

from cjs-module-lexer.

guybedford avatar guybedford commented on June 9, 2024

The latest update has been upstreamed now, and the object form detection remains the same without string support. I'm open to further suggestions here, although the window is closing on the current set of updates. Closing for now but just let me know if we should reopen or make changes here further.

from cjs-module-lexer.

evanw avatar evanw commented on June 9, 2024

it doesn't even have an expression parser

Ah, this makes sense. I was mainly just surprised that support for this wasn't necessary to handle modules like that in the wild.

I recently shipped support for the 0 && module.exports = {...} pattern in esbuild btw. So far so good.

from cjs-module-lexer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.