check `node.raw` before checking because it's not standard and may break custom parser
See original GitHub issueWhat rule do you want to change?
https://github.com/eslint/eslint/search?q=node.raw&type=
Does this change cause the rule to produce more or fewer warnings?
Fewer error for custom parser, raw
of Literal
is not standard, see https://github.com/estree/estree/issues/14
How will the change be implemented? (New option, new default behavior, etc.)?
check node.raw
, return if not presented
Please provide some example code that this change will affect:
Context: https://github.com/mdx-js/eslint-mdx/pull/284#issuecomment-800399534
What does the rule currently do for this code?
break if the custom parser does not have node.raw
What will the rule do after it’s changed?
no error
Are you willing to submit a pull request to implement this change?
Yes
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:11 (7 by maintainers)
Top Results From Across the Web
Jest tests failed after upgrading axios to v1.1.2 · Issue #5101
The following fix works for now but I expect a standard fix for this issue. "test": "react-scripts test --transformIgnorePatterns \"node_modules ...
Read more >Parsing huge logfiles in Node.js - read in line-by-line
The following solution can parse very large files, line by line using stream & pipe. For testing I used a 2.1 gb file...
Read more >Process | Node.js v19.3.0 Documentation
The 'beforeExit' event is emitted when Node.js empties its event loop and has no additional work to schedule. Normally, the Node.js process will...
Read more >Why the Hell Would I Use Node.js? A Case-by-case Tutorial
Node.js can solve I/O scaling, but was not created to compute scaling problems. Learn why and when to use Node.js in this case-by-case...
Read more >Mocha - the fun, simple, flexible JavaScript test framework
Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser ... Tests can appear before, after, or interspersed with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Specifically, fewer crashes.
My use case for this is that certain languages can compile to JavaScript. Such as markdown/MDX, and others. But those language have different and noncompatible representations of literals.
For example, in markdown, an
alt
attribute can be represented with![the alt attribute]()
. A custom parser could represent that attribute as a JSX attribute in estree. But in those cases, setting araw
field on the literal is nonsensical: there are no quotes, escapes don‘t work, character references (&
) could exist, etc.A different solution for custom parsers would be to try and create a sensical
.raw
attribute. The problem with this approach though is that it now needs to know what the preferred quote style is.So, I think a better solution would be for rules that can only work on
.raw
to exit gracefully if that field does not exist.Tokens, or slicing text from the source code by node’s
.range
.Rules that need
.raw
are mostly rules with a purpose to check how the code was exactly written in JS and enforce some style or best practices about it. Those rules are thus not applicable to languages with a different syntax for literals.If we treat an absence of
.raw
as a way to tell that it isn’t really a JS literal, that would add maintenance to rules that were designed for JS. It could also hide bugs in rules and other parsers.You’ll produce a single AST with JS and non-JS parts, where some
Literal
nodes have.raw
but some don’t?