Improve template tokenizing (#13919)
* add benchmarks * refactor: tokenize template as middle + tail * perf: avoid push tc.brace * refactor: overwrite skipSpace in jsx plugin * transform tl.templateMiddle/Tail * refactor: simplify JSX context tracking * fix flow error * refactor: move JSX context to context.js * fix: ensure comment stack is correctly handled * rename createPositionFromPosition * rename token type and methods * add tokenIsTemplate * refactor: merge babel 7 logic in babel7CompatTokens * fix flow error
This commit is contained in:
@@ -50,3 +50,22 @@ export function getLineInfo(input: string, offset: number): Position {
|
||||
|
||||
return new Position(line, offset - lineStart);
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a new position with a non-zero column offset from the given position.
|
||||
* This function should be only be used when we create AST node out of the token
|
||||
* boundaries, such as TemplateElement ends before tt.templateNonTail. This
|
||||
* function does not skip whitespaces.
|
||||
*
|
||||
* @export
|
||||
* @param {Position} position
|
||||
* @param {number} columnOffset
|
||||
* @returns {Position}
|
||||
*/
|
||||
export function createPositionWithColumnOffset(
|
||||
position: Position,
|
||||
columnOffset: number,
|
||||
) {
|
||||
const { line, column } = position;
|
||||
return new Position(line, column + columnOffset);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user