lib/parser/micro-template-eslint-parser.js
function parseTemplate(code, parserOptions) {
    const sourceCodeStore = new SourceCodeStore(code)

    // 文字位置をそのままにしてscriptとhtmlを分解
    let script = ""
    let pre = 0
    let template = ""
    const microTemplateTokens = [] // テンプレートTokens
    for (const token of genMicroTemplateTokens(
        code,
        parserOptions,
        sourceCodeStore
    )) {
        microTemplateTokens.push(token)
        const start = token.start
        const end = token.end

        const part = code.slice(pre, start)
        script += replaceToWhitespace(part)
        template += part

        const scriptBeforeBase = token.expressionStart.chars
        const scriptAfterBase = token.expressionEnd.chars
        const scriptBefore = replaceToWhitespace(scriptBeforeBase)
        let scriptAfter = replaceToWhitespace(scriptAfterBase)
        if (token.type !== "MicroTemplateEvaluate") {
            scriptAfter = scriptAfter.replace(/ /u, ";")
        }
        script += `${scriptBefore}${token.code}${scriptAfter}`

        template += replaceToWhitespace(code.slice(start, end))

        pre = end
    }
    const part = code.slice(pre, code.length)
    script += replaceToWhitespace(part)
    template += part

    const scriptResult = parseScript(script, parserOptions)

    sourceCodeStore.template = template
    sourceCodeStore.script = script

    const service = new MicroTemplateService({
        code,
        template,
        script,
        microTemplateTokens,
        sourceCodeStore,
        ast: scriptResult.ast,
    })
    container.addService(parserOptions.filePath, service)
    scriptResult.services = Object.assign(scriptResult.services || {}, {
        getMicroTemplateService() {
            return service
        },
    })
    return scriptResult
}
function parseTemplate(code, parserOptions) {
    const sourceCodeStore = new SourceCodeStore(code)

    // 文字位置をそのままにしてscriptとhtmlを分解
    let script = ""
    let pre = 0
    let template = ""
    const microTemplateTokens = [] // テンプレートTokens
    for (const token of genMicroTemplateTokens(
        code,
        parserOptions,
        sourceCodeStore
    )) {
        microTemplateTokens.push(token)
        const start = token.start
        const end = token.end

        const part = code.slice(pre, start)
        script += replaceToWhitespace(part)
        template += part

        const scriptBeforeBase = token.expressionStart.chars
        const scriptAfterBase = token.expressionEnd.chars
        const scriptBefore = replaceToWhitespace(scriptBeforeBase)
        let scriptAfter = replaceToWhitespace(scriptAfterBase)
        if (token.type !== "MicroTemplateEvaluate") {
            scriptAfter = scriptAfter.replace(/ /u, ";")
        }
        script += `${scriptBefore}${token.code}${scriptAfter}`

        template += replaceToWhitespace(code.slice(start, end))

        pre = end
    }
    const part = code.slice(pre, code.length)
    script += replaceToWhitespace(part)
    template += part

    const scriptResult = parseScript(script, parserOptions)

    sourceCodeStore.template = template
    sourceCodeStore.script = script

    const service = new MicroTemplateService({
        code,
        template,
        script,
        microTemplateTokens,
        sourceCodeStore,
        ast: scriptResult.ast,
    })
    container.addService(parserOptions.filePath, service)
    scriptResult.services = Object.assign(scriptResult.services || {}, {
        getMicroTemplateService() {
            return service
        },
    })
    return scriptResult
}
function parseTemplate ( code , parserOptions ) { const sourceCodeStore = new SourceCodeStore ( code ) // 文字位置をそのままにしてscriptとhtmlを分解 let script = "" let pre = 0 let template = "" const microTemplateTokens = [ ] // テンプレートTokens for ( const token of genMicroTemplateTokens ( code , parserOptions , sourceCodeStore ) ) { microTemplateTokens . push ( token ) const start = token . start const end = token . end const part = code . slice ( pre , start ) script += replaceToWhitespace ( part ) template += part const scriptBeforeBase = token . expressionStart . chars const scriptAfterBase = token . expressionEnd . chars const scriptBefore = replaceToWhitespace ( scriptBeforeBase ) let scriptAfter = replaceToWhitespace ( scriptAfterBase ) if ( token . type !== "MicroTemplateEvaluate" ) { scriptAfter = scriptAfter . replace ( / / u , ";" ) } script += ` ${ scriptBefore } ${ token . code } ${ scriptAfter } ` template += replaceToWhitespace ( code . slice ( start , end ) ) pre = end } const part = code . slice ( pre , code . length ) script += replaceToWhitespace ( part ) template += part const scriptResult = parseScript ( script , parserOptions ) sourceCodeStore . template = template sourceCodeStore . script = script const service = new MicroTemplateService ( { code , template , script , microTemplateTokens , sourceCodeStore , ast : scriptResult . ast , } ) container . addService ( parserOptions . filePath , service ) scriptResult . services = Object . assign ( scriptResult . services || { } , { getMicroTemplateService ( ) { return service } , } ) return scriptResult }
Parse the given template.
@param {string} code The template to parse.
@param {object} parserOptions The parser options.
@returns {object} The parsing result.
Parse the given template .