From d48a2aedd54370b2c2ff613288aa53bec8ca25c6 Mon Sep 17 00:00:00 2001 From: Edward Faulkner Date: Thu, 10 Jun 2021 17:18:27 -0400 Subject: [PATCH 01/19] dropping ember-templates-imports stuff It doesn't belong in here. --- .../preprocess-embedded-templates-tests.js | 1071 ----------------- __tests__/template-literal-tests.js | 709 ----------- __tests__/template-tag-tests.js | 761 ------------ __tests__/tests.js | 18 +- index.js | 6 +- 5 files changed, 5 insertions(+), 2560 deletions(-) delete mode 100644 __tests__/preprocess-embedded-templates-tests.js delete mode 100644 __tests__/template-literal-tests.js delete mode 100644 __tests__/template-tag-tests.js diff --git a/__tests__/preprocess-embedded-templates-tests.js b/__tests__/preprocess-embedded-templates-tests.js deleted file mode 100644 index c225c6e7..00000000 --- a/__tests__/preprocess-embedded-templates-tests.js +++ /dev/null @@ -1,1071 +0,0 @@ -const { preprocessEmbeddedTemplates } = require('../index'); -const { stripIndent } = require('common-tags'); - -const getTemplateLocalsRequirePath = require.resolve('@glimmer/syntax'); -const { getTemplateLocals } = require('@glimmer/syntax'); - -const EAGER_TEMPLATE_TAG_CONFIG = { - getTemplateLocals, - - templateTag: 'template', - templateTagReplacement: 'GLIMMER_TEMPLATE', - - relativePath: '/foo/bar.gjs', - includeSourceMaps: false, - includeTemplateTokens: true, -}; - -const TEMPLATE_TAG_CONFIG = { - getTemplateLocalsRequirePath, - getTemplateLocalsExportPath: 'getTemplateLocals', - - templateTag: 'template', - templateTagReplacement: 'GLIMMER_TEMPLATE', - - relativePath: '/foo/bar.gjs', - includeSourceMaps: false, - includeTemplateTokens: true, -}; - -const TEMPLATE_LITERAL_CONFIG = { - getTemplateLocalsRequirePath, - getTemplateLocalsExportPath: 'getTemplateLocals', - - importIdentifier: 'hbs', - importPath: 'ember-template-imports', - - relativePath: '/foo/bar.js', - includeSourceMaps: false, - includeTemplateTokens: true, -}; - -describe('htmlbars-inline-precompile: preprocessEmbeddedTemplates', () => { - describe('template tag', () => { - it('works with eager config', () => { - let preprocessed = preprocessEmbeddedTemplates( - stripIndent` - - `, - EAGER_TEMPLATE_TAG_CONFIG - ); - - expect(preprocessed).toMatchInlineSnapshot(` - Object { - "output": "[GLIMMER_TEMPLATE(\`Hello, world!\`)]", - "replacements": Array [ - Object { - "index": 0, - "newLength": 19, - "oldLength": 10, - "originalCol": 1, - "originalLine": 1, - "type": "start", - }, - Object { - "index": 23, - "newLength": 3, - "oldLength": 11, - "originalCol": 24, - "originalLine": 1, - "type": "end", - }, - ], - } - `); - }); - - it('works with basic templates', () => { - let preprocessed = preprocessEmbeddedTemplates( - stripIndent` - - `, - TEMPLATE_TAG_CONFIG - ); - - expect(preprocessed).toMatchInlineSnapshot(` - Object { - "output": "[GLIMMER_TEMPLATE(\`Hello, world!\`)]", - "replacements": Array [ - Object { - "index": 0, - "newLength": 19, - "oldLength": 10, - "originalCol": 1, - "originalLine": 1, - "type": "start", - }, - Object { - "index": 23, - "newLength": 3, - "oldLength": 11, - "originalCol": 24, - "originalLine": 1, - "type": "end", - }, - ], - } - `); - }); - - it('works with templates assigned to variables', () => { - let preprocessed = preprocessEmbeddedTemplates( - stripIndent` - const Foo = - `, - TEMPLATE_TAG_CONFIG - ); - - expect(preprocessed).toMatchInlineSnapshot(` - Object { - "output": "const Foo = [GLIMMER_TEMPLATE(\`Hello, world!\`)]", - "replacements": Array [ - Object { - "index": 12, - "newLength": 19, - "oldLength": 10, - "originalCol": 13, - "originalLine": 1, - "type": "start", - }, - Object { - "index": 35, - "newLength": 3, - "oldLength": 11, - "originalCol": 36, - "originalLine": 1, - "type": "end", - }, - ], - } - `); - }); - - it('works with nested templates', () => { - let preprocessed = preprocessEmbeddedTemplates( - stripIndent` - - `, - TEMPLATE_TAG_CONFIG - ); - - expect(preprocessed).toMatchInlineSnapshot(` - Object { - "output": "[GLIMMER_TEMPLATE(\` - - \`)]", - "replacements": Array [ - Object { - "index": 0, - "newLength": 19, - "oldLength": 10, - "originalCol": 1, - "originalLine": 1, - "type": "start", - }, - Object { - "index": 48, - "newLength": 3, - "oldLength": 11, - "originalCol": 1, - "originalLine": 3, - "type": "end", - }, - ], - } - `); - }); - - it('it does not process templates in strings', () => { - let preprocessed = preprocessEmbeddedTemplates( - stripIndent` - const Foo = - const foo = ""; - const Bar = - const bar = ''; - const Baz = - const baz = \` - - \`; - - - const regex = /