Skip to content

Commit

Permalink
This may take some actual attention
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Sep 30, 2023
1 parent b88f06f commit d40ce63
Showing 1 changed file with 9 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -37,28 +34,24 @@ export const preprocess: GlintExtensionPreprocess<PreprocessData> = (source, pat
let templateLocations: Array<TemplateLocation> = [];
let segments: Array<string> = [];
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;

Expand Down

0 comments on commit d40ce63

Please sign in to comment.