From d40ce63229bf2c02dcc8760be0bc7cd50d32483b Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Sat, 30 Sep 2023 16:54:14 -0400 Subject: [PATCH] This may take some actual attention --- .../-private/environment/preprocess.ts | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/packages/environment-ember-template-imports/-private/environment/preprocess.ts b/packages/environment-ember-template-imports/-private/environment/preprocess.ts index 754c2a1fb..9c004ceee 100644 --- a/packages/environment-ember-template-imports/-private/environment/preprocess.ts +++ b/packages/environment-ember-template-imports/-private/environment/preprocess.ts @@ -1,14 +1,11 @@ import { GlintExtensionPreprocess } from '@glint/core/config-types'; -import { GLOBAL_TAG, PreprocessData, TemplateLocation } from './common'; +import { PreprocessData, TemplateLocation } from './common'; // NOTE: This import is a lie -- We are not real ESM, and this is compiled to CJS. // ESM usage would be different here. import { Preprocessor } from 'content-tag'; const p = new Preprocessor(); -const TEMPLATE_START = `[${GLOBAL_TAG}\``; -const TEMPLATE_END = '`]'; - interface Parsed { type: 'expression' | 'class-member'; tagName: 'template'; @@ -37,28 +34,24 @@ export const preprocess: GlintExtensionPreprocess = (source, pat let templateLocations: Array = []; let segments: Array = []; let sourceOffset = 0; - let delta = 0; for (let template of templates) { - let { start, end } = template; - let startTagLength = template.start[0].length; - let endTagLength = template.end[0].length; - let startTagOffset = start.index ?? -1; - let endTagOffset = end.index ?? -1; + let startTagLength = template.startRange.end - template.startRange.start; + let endTagLength = template.endRange.end - template.endRange.start; + let startTagOffset = template.contentRange.start; + let endTagOffset = template.contentRange.end; if (startTagOffset === -1 || endTagOffset === -1) continue; - let transformedStart = startTagOffset - delta; + let transformedStart = startTagOffset; segments.push(source.slice(sourceOffset, startTagOffset)); - segments.push(TEMPLATE_START); - delta += startTagLength - TEMPLATE_START.length; + segments.push(source.slice(template.startRange.start, template.startRange.end)); - let transformedEnd = endTagOffset - delta + TEMPLATE_END.length; + let transformedEnd = endTagOffset; segments.push(source.slice(startTagOffset + startTagLength, endTagOffset)); - segments.push(TEMPLATE_END); - delta += endTagLength - TEMPLATE_END.length; + segments.push(source.slice(template.endRange.start, template.endRange.end)); sourceOffset = endTagOffset + endTagLength;