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

Support loose (invalid) JavaScript #267

Open
4 tasks done
remcohaszing opened this issue Jan 13, 2023 · 3 comments
Open
4 tasks done

Support loose (invalid) JavaScript #267

remcohaszing opened this issue Jan 13, 2023 · 3 comments
Labels
🗄 area/interface This affects the public interface 👋 phase/new Post is being triaged automatically 🦋 type/enhancement This is great to have

Comments

@remcohaszing
Copy link
Member

remcohaszing commented Jan 13, 2023

Initial checklist

Problem

While typing, code is often invalid. Various IntelliSense features typically work on invalid code. TypeScript supports this, but acorn does not. Currently invalid syntax is caught, but IntelliSense doesn’t work. We need to find a way to deal with invalid syntax.

Solution

Needs investigation

Alternatives

🤷

@remcohaszing remcohaszing added 🦋 type/enhancement This is great to have 🗄 area/interface This affects the public interface 👋 phase/new Post is being triaged automatically labels Jan 13, 2023
@ChristianMurphy
Copy link
Member

Maybe https://github.com/acornjs/acorn/tree/master/acorn-loose/ would be of interest?

@wooorm
Copy link
Member

wooorm commented Jan 20, 2023

the micromark utils do a low an acorn instance to be passed, so that might also indeed allow the loose version? Worth to check, but might not be strong enough

@remcohaszing
Copy link
Member Author

I think acorn-loose is a good candidate, although currently it doesn’t work as a drop-in replacement, because it doesn’t implement parseExpressionAt.

import {Parser} from 'acorn'
import {LooseParser} from 'acorn-loose'
import jsx from 'acorn-jsx'
import remarkMdx from 'remark-mdx'
import remarkParse from 'remark-parse'
import {unified} from 'unified'

// const parser = Parser.extend(jsx())
const parser = LooseParser.extend(jsx())

const processor = unified().use(remarkParse).use(remarkMdx, {acorn: parser})

const mdx = `
import { Button } from './button.js'

Click the button

<Button>Click me!</Button>
`

console.dir(processor.parse(mdx))

Also worth considering is @typescript-eslint/typescript-estree, or possibly even just TypeScript, as we’re not really interested in the estree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗄 area/interface This affects the public interface 👋 phase/new Post is being triaged automatically 🦋 type/enhancement This is great to have
Development

No branches or pull requests

3 participants