From b50562946646831acd2626c07da0e6176c5b2ac2 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Tue, 16 Mar 2021 09:22:31 -0400 Subject: [PATCH] Ensure Entities are never transformed in codemod mode. The prior changes (in 458fe54899c942f69f26cf789fa5339627f2fa81) ensured that **named** entities were never matched (things like ` `) but still allowed matching of char codes (hex or base 10). This ensures that **no** entities can be matched. --- .../syntax/lib/parser/tokenizer-event-handlers.ts | 13 ++++++++++++- .../@glimmer/syntax/test/generation/print-test.ts | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/@glimmer/syntax/lib/parser/tokenizer-event-handlers.ts b/packages/@glimmer/syntax/lib/parser/tokenizer-event-handlers.ts index 09ce7d6ea..582d66cda 100644 --- a/packages/@glimmer/syntax/lib/parser/tokenizer-event-handlers.ts +++ b/packages/@glimmer/syntax/lib/parser/tokenizer-event-handlers.ts @@ -381,6 +381,17 @@ const syntax: Syntax = { Walker, }; +class CodemodEntityParser extends EntityParser { + // match upstream types, but never match an entity + constructor() { + super({}); + } + + parse(): string | undefined { + return undefined; + } +} + export function preprocess( input: string | Source | HBS.Program, options: PreprocessOptions = {} @@ -412,7 +423,7 @@ export function preprocess( let entityParser = undefined; if (mode === 'codemod') { - entityParser = new EntityParser({}); + entityParser = new CodemodEntityParser(); } let offsets = SourceSpan.forCharPositions(source, 0, source.source.length); diff --git a/packages/@glimmer/syntax/test/generation/print-test.ts b/packages/@glimmer/syntax/test/generation/print-test.ts index ac4688f25..7c13cf923 100644 --- a/packages/@glimmer/syntax/test/generation/print-test.ts +++ b/packages/@glimmer/syntax/test/generation/print-test.ts @@ -114,6 +114,8 @@ QUnit.module('[glimmer-syntax] Code generation - source -> source', function () // "stand alone" ' {{#foo}}\n {{bar}}\n {{/foo}}', + + ``, ].forEach(buildTest); });