@@ -59,6 +59,7 @@ import {
5959 getScriptSetupParserOptions ,
6060} from "../script-setup/parser-options"
6161import { isScriptSetupElement } from "../common/ast-utils"
62+ import type { LinesAndColumns } from "../common/lines-and-columns"
6263
6364// [1] = aliases.
6465// [2] = delimiter.
@@ -563,13 +564,15 @@ export function parseScript(
563564/**
564565 * Parse the source code of the given `<script>` element.
565566 * @param node The `<script>` element to parse.
566- * @param globalLocationCalculator The location calculator for fixLocations.
567+ * @param sfcCode The source code of SFC.
568+ * @param linesAndColumns The lines and columns location calculator.
567569 * @param parserOptions The parser options.
568570 * @returns The result of parsing.
569571 */
570572export function parseScriptElement (
571573 node : VElement ,
572- globalLocationCalculator : LocationCalculatorForHtml ,
574+ sfcCode : string ,
575+ linesAndColumns : LinesAndColumns ,
573576 originalParserOptions : ParserOptions ,
574577) : ESLintExtendedProgram {
575578 const parserOptions : ParserOptions = isScriptSetupElement ( node )
@@ -580,13 +583,19 @@ export function parseScriptElement(
580583 originalParserOptions . ecmaVersion || DEFAULT_ECMA_VERSION ,
581584 }
582585
583- const text = node . children [ 0 ]
584- const { code, offset } =
585- text != null && text . type === "VText"
586- ? { code : text . value , offset : text . range [ 0 ] }
587- : { code : "" , offset : node . startTag . range [ 1 ] }
586+ let code : string
587+ let offset : number
588+ const textNode = node . children [ 0 ]
589+ if ( textNode != null && textNode . type === "VText" ) {
590+ const [ scriptStartOffset , scriptEndOffset ] = textNode . range
591+ code = sfcCode . slice ( scriptStartOffset , scriptEndOffset )
592+ offset = scriptStartOffset
593+ } else {
594+ code = ""
595+ offset = node . startTag . range [ 1 ]
596+ }
588597 const locationCalculator =
589- globalLocationCalculator . getSubCalculatorAfter ( offset )
598+ linesAndColumns . createOffsetLocationCalculator ( offset )
590599 const result = parseScriptFragment ( code , locationCalculator , parserOptions )
591600
592601 // Needs the tokens of start/end tags for `lines-around-*` rules to work
0 commit comments