Skip to content

Commit

Permalink
fix(jsx): fix JSXIdentifier literal value range and loc
Browse files Browse the repository at this point in the history
closes #127
  • Loading branch information
3cp committed Oct 27, 2020
1 parent 11765ce commit 076e454
Show file tree
Hide file tree
Showing 2 changed files with 194 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/lexer/jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import { advanceChar, LexerState, TokenLookup, scanSingleToken, scanNewLine, con
* @param context Context masks
*/
export function scanJSXAttributeValue(parser: ParserState, context: Context): Token {
parser.startPos = parser.index;
parser.startColumn = parser.column;
parser.startLine = parser.line;
parser.startPos = parser.tokenPos = parser.index;
parser.startColumn = parser.colPos = parser.column;
parser.startLine = parser.linePos = parser.line;
parser.token =
CharTypes[parser.currentChar] & CharFlags.StringLiteral
? scanJSXString(parser)
Expand Down
200 changes: 191 additions & 9 deletions test/parser/miscellaneous/jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1747,7 +1747,7 @@ describe('Miscellaneous - JSX', () => {
],
[
`<div id={aa} class="className" ></div>`,
Context.OptionsJSX,
Context.OptionsJSX | Context.OptionsRanges | Context.OptionsLoc,
{
type: 'Program',
sourceType: 'script',
Expand All @@ -1761,7 +1761,20 @@ describe('Miscellaneous - JSX', () => {
type: 'JSXOpeningElement',
name: {
type: 'JSXIdentifier',
name: 'div'
name: 'div',
start: 1,
end: 4,
range: [1, 4],
loc: {
start: {
line: 1,
column: 1
},
end: {
line: 1,
column: 4
}
}
},
attributes: [
{
Expand All @@ -1770,38 +1783,207 @@ describe('Miscellaneous - JSX', () => {
type: 'JSXExpressionContainer',
expression: {
type: 'Identifier',
name: 'aa'
name: 'aa',
start: 9,
end: 11,
range: [9, 11],
loc: {
start: {
line: 1,
column: 9
},
end: {
line: 1,
column: 11
}
}
},
start: 8,
end: 12,
range: [8, 12],
loc: {
start: {
line: 1,
column: 8
},
end: {
line: 1,
column: 12
}
}
},
name: {
type: 'JSXIdentifier',
name: 'id'
name: 'id',
start: 5,
end: 7,
range: [5, 7],
loc: {
start: {
line: 1,
column: 5
},
end: {
line: 1,
column: 7
}
}
},
start: 5,
end: 12,
range: [5, 12],
loc: {
start: {
line: 1,
column: 5
},
end: {
line: 1,
column: 12
}
}
},
{
type: 'JSXAttribute',
value: {
type: 'Literal',
value: 'className'
value: 'className',
start: 19,
end: 30,
range: [19, 30],
loc: {
start: {
line: 1,
column: 19
},
end: {
line: 1,
column: 30
}
}
},
name: {
type: 'JSXIdentifier',
name: 'class'
name: 'class',
start: 13,
end: 18,
range: [13, 18],
loc: {
start: {
line: 1,
column: 13
},
end: {
line: 1,
column: 18
}
}
},
start: 13,
end: 30,
range: [13, 30],
loc: {
start: {
line: 1,
column: 13
},
end: {
line: 1,
column: 30
}
}
}
],
selfClosing: false
selfClosing: false,
start: 0,
end: 32,
range: [0, 32],
loc: {
start: {
line: 1,
column: 0
},
end: {
line: 1,
column: 32
}
}
},
closingElement: {
type: 'JSXClosingElement',
name: {
type: 'JSXIdentifier',
name: 'div'
name: 'div',
start: 34,
end: 37,
range: [34, 37],
loc: {
start: {
line: 1,
column: 34
},
end: {
line: 1,
column: 37
}
}
},
start: 32,
end: 38,
range: [32, 38],
loc: {
start: {
line: 1,
column: 32
},
end: {
line: 1,
column: 38
}
}
},
start: 0,
end: 38,
range: [0, 38],
loc: {
start: {
line: 1,
column: 0
},
end: {
line: 1,
column: 38
}
}
},
start: 0,
end: 38,
range: [0, 38],
loc: {
start: {
line: 1,
column: 0
},
end: {
line: 1,
column: 38
}
}
}
]
],
start: 0,
end: 38,
range: [0, 38],
loc: {
start: {
line: 1,
column: 0
},
end: {
line: 1,
column: 38
}
}
}
],
[
Expand Down

0 comments on commit 076e454

Please sign in to comment.