Skip to content

Commit

Permalink
fix: add support for private methods
Browse files Browse the repository at this point in the history
  • Loading branch information
barelyhuman committed Dec 24, 2023
1 parent e8f714b commit bfac046
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 6 deletions.
6 changes: 4 additions & 2 deletions lib/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ const classFields = require('acorn-class-fields')
const { importAssertions } = require('acorn-import-assertions')
const staticClassFeatures = require('acorn-static-class-features')
const privateClassFields = require('acorn-private-class-elements')
const privateMethods = require('acorn-private-methods')

const jsxParser = acorn.Parser.extend(
jsx(),
privateClassFields,
privateMethods,
classFields,
importAssertions,
staticClassFeatures,
privateClassFields
staticClassFeatures
)

exports.astFromCode = astFromCode
Expand Down
22 changes: 18 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"acorn-jsx": "^5.3.1",
"acorn-jsx-walk": "^2.0.0",
"acorn-logical-assignment": "^0.1.4",
"acorn-loose": "^8.4.0",
"acorn-private-class-elements": "^1.0.0",
"acorn-private-methods": "^1.0.0",
"acorn-static-class-features": "^1.0.0",
Expand Down
36 changes: 36 additions & 0 deletions tests/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,4 +300,40 @@ export default function IslandComponent(props) {
)
})

test('parse island with a private class method', async () => {
const output = generateIslandsWithSource(
`
class Hello {
constructor(){}
#privateMethod(){}
}
export default function Component(){
return <p>hello</p>
}
`,
'./index.jsx',
{
rootDir: '.',
client: {
output: '.islands',
},
}
)

await inlineSnapshot(
output.code.server,
`
class Hello {
constructor(){}
#privateMethod(){}
}
export default function Component(){
return <p>hello</p>
}
`
)
})

test.run()

0 comments on commit bfac046

Please sign in to comment.