Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

Pass through filename as modulename to precompile #475

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion __tests__/template-literal-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const babel = require('@babel/core');
const HTMLBarsInlinePrecompile = require('../index');
const TransformModules = require('@babel/plugin-transform-modules-amd');
const { join } = require('path');

const { preprocessEmbeddedTemplates } = HTMLBarsInlinePrecompile;

Expand All @@ -18,13 +19,15 @@ const TEMPLATE_LITERAL_CONFIG = {
includeTemplateTokens: true,
};

const FILENAME = join(process.cwd(), 'foo-bar.js');

describe('htmlbars-inline-precompile: useTemplateLiteralProposalSemantics', function () {
let precompile, plugins, optionsReceived;

function transform(code) {
return babel
.transform(code, {
filename: 'foo-bar.js',
filename: FILENAME,
plugins,
})
.code.trim();
Expand Down Expand Up @@ -238,6 +241,9 @@ describe('htmlbars-inline-precompile: useTemplateLiteralProposalSemantics', func
isProduction: undefined,
locals: ['baz', 'foo', 'bar'],
strictMode: true,
meta: {
moduleName: FILENAME,
},
});
});

Expand Down Expand Up @@ -502,6 +508,9 @@ describe('htmlbars-inline-precompile: useTemplateLiteralProposalSemantics', func
isProduction: undefined,
locals: ['Baz', 'foo', 'bar'],
strictMode: true,
meta: {
moduleName: FILENAME,
},
});
});

Expand Down
11 changes: 10 additions & 1 deletion __tests__/template-tag-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const babel = require('@babel/core');
const HTMLBarsInlinePrecompile = require('../index');
const TransformModules = require('@babel/plugin-transform-modules-amd');
const { join } = require('path');

const { preprocessEmbeddedTemplates } = HTMLBarsInlinePrecompile;

Expand All @@ -18,13 +19,15 @@ const TEMPLATE_TAG_CONFIG = {
includeTemplateTokens: true,
};

const FILENAME = join(process.cwd(), 'foo-bar.js');

describe('htmlbars-inline-precompile: useTemplateTagProposalSemantics', function () {
let precompile, plugins, optionsReceived;

function transform(code) {
return babel
.transform(code, {
filename: 'foo-bar.js',
filename: FILENAME,
plugins,
})
.code.trim();
Expand Down Expand Up @@ -243,6 +246,9 @@ describe('htmlbars-inline-precompile: useTemplateTagProposalSemantics', function
isProduction: undefined,
locals: ['baz', 'foo', 'bar'],
strictMode: true,
meta: {
moduleName: FILENAME,
},
});
});

Expand Down Expand Up @@ -560,6 +566,9 @@ describe('htmlbars-inline-precompile: useTemplateTagProposalSemantics', function
isProduction: undefined,
locals: ['Baz', 'foo', 'bar'],
strictMode: true,
meta: {
moduleName: FILENAME,
},
});
});

Expand Down
44 changes: 43 additions & 1 deletion __tests__/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ const TransformTemplateLiterals = require('@babel/plugin-transform-template-lite
const TransformModules = require('@babel/plugin-transform-modules-amd');
const TransformUnicodeEscapes = require('@babel/plugin-transform-unicode-escapes');
const { stripIndent } = require('common-tags');
const { join } = require('path');

const FILENAME = join(process.cwd(), 'foo-bar.js');

describe('htmlbars-inline-precompile', function () {
let precompile, plugins, optionsReceived;

function transform(code) {
return babel
.transform(code, {
filename: 'foo-bar.js',
filename: FILENAME,
plugins,
})
.code.trim();
Expand Down Expand Up @@ -118,6 +121,9 @@ describe('htmlbars-inline-precompile', function () {

expect(optionsReceived).toEqual({
contents: source,
meta: {
moduleName: FILENAME,
},
});
});

Expand All @@ -144,6 +150,9 @@ describe('htmlbars-inline-precompile', function () {
expect(optionsReceived).toEqual({
contents: source,
isProduction: true,
meta: {
moduleName: FILENAME,
},
});
});

Expand All @@ -170,6 +179,9 @@ describe('htmlbars-inline-precompile', function () {
expect(optionsReceived).toEqual({
contents: source,
isProduction: true,
meta: {
moduleName: FILENAME,
},
});
});

Expand Down Expand Up @@ -197,6 +209,9 @@ describe('htmlbars-inline-precompile', function () {
isProduction: true,
locals: null,
strictMode: false,
meta: {
moduleName: FILENAME,
},
});
});

Expand All @@ -206,6 +221,9 @@ describe('htmlbars-inline-precompile', function () {

expect(optionsReceived).toEqual({
contents: source,
meta: {
moduleName: FILENAME,
},
});
});

Expand Down Expand Up @@ -240,6 +258,9 @@ describe('htmlbars-inline-precompile', function () {
stringifiedThing: {
foo: 'baz',
},
meta: {
moduleName: FILENAME,
},
});
});

Expand Down Expand Up @@ -312,6 +333,9 @@ describe('htmlbars-inline-precompile', function () {
isProduction: undefined,
locals: null,
strictMode: false,
meta: {
moduleName: FILENAME,
},
});
});

Expand Down Expand Up @@ -861,6 +885,9 @@ describe('htmlbars-inline-precompile', function () {
expect(optionsReceived).toEqual({
contents: source,
locals: ['foo', 'bar'],
meta: {
moduleName: FILENAME,
},
});
});

Expand All @@ -873,6 +900,9 @@ describe('htmlbars-inline-precompile', function () {
expect(optionsReceived).toEqual({
contents: source,
locals: ['foo', 'bar'],
meta: {
moduleName: FILENAME,
},
});
});

Expand All @@ -884,6 +914,9 @@ describe('htmlbars-inline-precompile', function () {
expect(optionsReceived).toEqual({
contents: source,
locals: ['foo', 'bar'],
meta: {
moduleName: FILENAME,
},
});
});

Expand All @@ -895,6 +928,9 @@ describe('htmlbars-inline-precompile', function () {
expect(optionsReceived).toEqual({
contents: source,
locals: ['foo', 'bar'],
meta: {
moduleName: FILENAME,
},
});
});

Expand All @@ -906,6 +942,9 @@ describe('htmlbars-inline-precompile', function () {
expect(optionsReceived).toEqual({
contents: source,
locals: ['foo', 'bar'],
meta: {
moduleName: FILENAME,
},
});
});

Expand All @@ -917,6 +956,9 @@ describe('htmlbars-inline-precompile', function () {
expect(optionsReceived).toEqual({
contents: source,
locals: ['foo', 'bar'],
meta: {
moduleName: FILENAME,
},
});
});

Expand Down
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,9 @@ module.exports = function (babel) {
isProduction,
locals,
strictMode,
meta: {
moduleName: state.file.opts.filename,
},
}),
options
);
Expand Down Expand Up @@ -519,6 +522,10 @@ module.exports = function (babel) {
compilerOptions.strictMode = true;
}

compilerOptions.meta = {
moduleName: state.file.opts.filename,
};

replacePath(
path,
state,
Expand Down