Comments (4)
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.
@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.
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.
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)
- Extending exports object detections HOT 20
- add tag for 1.2.2 HOT 4
- node ES6 import throws this error. HOT 18
- Error selecting connection connect ECONNREFUSED 127.0.0.1:5432
- Function call changes in TypeScript 4.4 seem to be breaking detection of named exports HOT 7
- Can't export when enumerable is "!0"
- When trying to build with snowpack this error is thrown HOT 4
- Not work well with TypeScript export default as output HOT 2
- exports can be detected in hashbang
- Feature Request: Also detect esbuild Re-exports HOT 1
- Bug: cannot detect exported numbers HOT 5
- Incompatibility with TypeScript (edge case) HOT 3
- Issue with parsing 'react-transition-group' HOT 2
- Rollup ^3.0.0 cjs re-exports edge case with externalLiveBindings: false HOT 8
- Out of bounds memory access HOT 1
- Real world edge case: prettier HOT 1
- Add RISC-V Support HOT 2
- Unable to detect exports from bundled webpack output HOT 6
- Cannot load externalized builtin: "internal/deps/cjs-module-lexer/lexer:/usr/lib/node_modules/cjs-module-lexer/lexer.js". HOT 9
- Allow externalized Wasm build HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cjs-module-lexer.