diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..191ae4cc --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +*.d.ts \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js index e6e16efb..44f7d0f9 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -5,22 +5,16 @@ module.exports = { ecmaVersion: 2017, }, plugins: ['node', 'prettier'], - extends: [ - 'eslint:recommended', - 'plugin:node/recommended', - 'plugin:prettier/recommended', - ], + extends: ['eslint:recommended', 'plugin:node/recommended', 'plugin:prettier/recommended'], env: { node: true, }, - ignorePatterns: ['dist/**/*.js'], - rules: { }, + ignorePatterns: ['src/**/*.js', '__tests__/**/*.js'], + rules: {}, overrides: [ // test files { - files: [ - '__tests__/**/*.js', - ], + files: ['__tests__/**/*.js'], env: { jest: true, }, @@ -39,31 +33,40 @@ module.exports = { 'plugin:@typescript-eslint/recommended', ], rules: { - 'node/no-unsupported-features/es-syntax': ['error', { - 'ignores': ['modules'] - }], + 'prefer-const': 'off', + 'node/no-unsupported-features/es-syntax': [ + 'error', + { + ignores: ['modules'], + }, + ], 'node/no-missing-import': 'off', - '@typescript-eslint/no-explicit-any': 'error', + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/ban-ts-comment': 'off', '@typescript-eslint/explicit-function-return-type': 'error', '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }], + '@typescript-eslint/explicit-module-boundary-types': ['off'], // We should try to remove this eventually '@typescript-eslint/explicit-function-return-type': 'off', - '@typescript-eslint/ban-types': ['error', { - types: { - // we currently use `object` as "valid WeakMap key" in a lot of APIs - object: false, - } - }], + '@typescript-eslint/ban-types': [ + 'error', + { + types: { + // we currently use `object` as "valid WeakMap key" in a lot of APIs + object: false, + }, + }, + ], // disabling this one because of DEBUG APIs, if we ever find a better // way to suport those we should re-enable it '@typescript-eslint/no-non-null-assertion': 'off', '@typescript-eslint/no-use-before-define': 'off', - } + }, }, ], }; diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 89e39ad1..6033226d 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -10,7 +10,7 @@ on: pull_request: {} schedule: - - cron: '0 6 * * 0' # weekly, on sundays + - cron: '0 6 * * 0' # weekly, on sundays jobs: lint: @@ -18,16 +18,16 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 - - uses: actions/setup-node@v1 - with: - node-version: 12.x - - name: install yarn - run: npm install -g yarn - - name: install dependencies - run: yarn install - - name: linting - run: yarn lint + - uses: actions/checkout@v1 + - uses: actions/setup-node@v1 + with: + node-version: 12.x + - name: install yarn + run: npm install -g yarn + - name: install dependencies + run: yarn install + - name: linting + run: yarn lint test: name: Tests @@ -35,32 +35,32 @@ jobs: strategy: matrix: - node: ['10', '12', '14'] + node: ['12', '14'] steps: - - uses: actions/checkout@v1 - - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node }} - - name: install yarn - run: npm install -g yarn - - name: install dependencies - run: yarn install - - name: test - run: yarn test + - uses: actions/checkout@v1 + - uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node }} + - name: install yarn + run: npm install -g yarn + - name: install dependencies + run: yarn install + - name: test + run: yarn test floating-test: name: Floating dependencies runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 - - uses: actions/setup-node@v1 - with: - node-version: '12.x' - - name: install yarn - run: npm install -g yarn - - name: install dependencies - run: yarn install --no-lockfile - - name: test - run: yarn test + - uses: actions/checkout@v1 + - uses: actions/setup-node@v1 + with: + node-version: '12.x' + - name: install yarn + run: npm install -g yarn + - name: install dependencies + run: yarn install --no-lockfile + - name: test + run: yarn test diff --git a/.gitignore b/.gitignore index 61a0ef8c..7e95d7d4 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,9 @@ node_modules /.eslintcache /dist yarn-error.log +/src/**/*.d.ts +/src/**/*.js +/src/**/*.js.map +/__tests__/**/*.d.ts +/__tests__/**/*.js +/__tests__/**/*.js.map diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..685ecebd --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,22 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Debug Jest Tests", + "type": "node", + "request": "launch", + "runtimeArgs": [ + "--inspect-brk", + "${workspaceRoot}/node_modules/.bin/jest", + "--runInBand", + "--no-cache" + ], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen", + "port": 9229 + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..cac0e10e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "editor.formatOnSave": true +} \ No newline at end of file diff --git a/__tests__/mock-precompile.js b/__tests__/mock-precompile.js deleted file mode 100644 index 65f90688..00000000 --- a/__tests__/mock-precompile.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - precompile(value) { - return `precompiledFromPath(${value})`; - }, -}; diff --git a/__tests__/mock-precompile.ts b/__tests__/mock-precompile.ts new file mode 100644 index 00000000..22e60fbf --- /dev/null +++ b/__tests__/mock-precompile.ts @@ -0,0 +1,3 @@ +export function precompile(value: string) { + return `precompiledFromPath(${value})`; +} 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 = /