Skip to content

Commit

Permalink
Fix strings detection (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi authored Sep 17, 2023
1 parent 18245fd commit f7c7082
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,19 @@ function tokenize(code) {
*/
function classify(token) {
const isLineBreak = token === '\n'
// First checking if they're attributes values
if (inJsxTag() && inStringQuotes()) {
return T_STRING
}
// Then determine if they're jsx literals
const isJsxLiterals = inJsxLiterals()
if (isJsxLiterals) {
return T_JSX_LITERALS

}
// Determine strings first before other types
if (inStringQuotes()) {
return T_STRING
} else if (keywords.has(token)) {
return last[1] === '.' ? T_IDENTIFIER : T_KEYWORD
} else if (isLineBreak) {
Expand Down
11 changes: 11 additions & 0 deletions test/ast.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,17 @@ describe('strings', () => {
'keyword', 'identifier', 'sign', 'string', 'string', 'string',
])
})

it('number in string', () => {
const code = `'123'\n'true'`
const tokens = tokenize(code)
expect(extractTokenValues(tokens)).toEqual([
"'", '123', "'", "'", 'true', "'",
])
expect(extractTokensTypes(tokens)).toEqual([
'string', 'string', 'string', 'break', 'string', 'string', 'string',
])
})
})

describe('class', () => {
Expand Down

1 comment on commit f7c7082

@vercel
Copy link

@vercel vercel bot commented on f7c7082 Sep 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

sugar-high – ./

sugar-high-huozhi.vercel.app
sugar-high.vercel.app
sugar-high-git-main-huozhi.vercel.app

Please sign in to comment.