Skip to content

Commit

Permalink
add back toc names for inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Jul 8, 2024
1 parent 80d3a8b commit a776d1d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ember-addon-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ let VersionChecker = require('ember-cli-version-checker');
module.exports = {
name: require('./package').name,

_getBabelOptions() {
const parentOptions = this.parent && this.parent.options;
const appOptions = this.app && this.app.options;
const addonOptions = parentOptions || appOptions || {};

addonOptions.babel = addonOptions.babel || {};
addonOptions.babel.plugins = addonOptions.babel.plugins || [];
return addonOptions.babel;
},

addBabelPlugin() {
this._getBabelOptions().plugins.push([
require.resolve('./src/babel-plugin.js'),
{ v: 1 },
]);
},

included() {
this._super.included.apply(this, arguments);

Expand Down Expand Up @@ -33,6 +50,8 @@ module.exports = {
'ember-template-imports requires' + '\n\t' + errors.join('\n\t'),
);
}

this.addBabelPlugin();
},

setupPreprocessorRegistry(type, registry) {
Expand Down
37 changes: 37 additions & 0 deletions src/babel-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const { basename, extname } = require('path');

module.exports = function hotReplaceAst(

Check failure on line 3 in src/babel-plugin.js

View workflow job for this annotation

GitHub Actions / Linting

Replace `⏎··{·types:·t·})·{⏎` with `{·types:·t·})·{`
{ types: t }) {

return {
name: 'add-template-only-names-for-inspector',
visitor: {
CallExpression(path, state) {
let calleePath = path.get('callee');

if (!calleePath.isIdentifier()) {
return;
}

if (calleePath.referencesImport('@ember/component/template-only', 'default')) {

Check failure on line 16 in src/babel-plugin.js

View workflow job for this annotation

GitHub Actions / Linting

Replace `calleePath.referencesImport('@ember/component/template-only',·'default')` with `⏎··········calleePath.referencesImport(⏎············'@ember/component/template-only',⏎············'default',⏎··········)⏎········`
let params = path.node.arguments;
let assignment = path.parentPath.parentPath.node;
let rootName = basename(state.filename).slice(0, -extname(state.filename).length);

Check failure on line 19 in src/babel-plugin.js

View workflow job for this annotation

GitHub Actions / Linting

Replace `0,·-extname(state.filename).length` with `⏎············0,⏎············-extname(state.filename).length,⏎··········`
let assignmentName = t.identifier('undefined');
if (assignment.type === 'AssignmentExpression' && assignment.left.type === 'Identifier') {

Check failure on line 21 in src/babel-plugin.js

View workflow job for this annotation

GitHub Actions / Linting

Replace `assignment.type·===·'AssignmentExpression'·&&·assignment.left.type·===·'Identifier'` with `⏎············assignment.type·===·'AssignmentExpression'·&&⏎············assignment.left.type·===·'Identifier'⏎··········`
assignmentName = t.stringLiteral(rootName + ':' + assignment.left.name);

Check failure on line 22 in src/babel-plugin.js

View workflow job for this annotation

GitHub Actions / Linting

Replace `rootName·+·':'·+·assignment.left.name` with `⏎··············rootName·+·':'·+·assignment.left.name,⏎············`
}
if (assignment.type === 'VariableDeclarator' && assignment.id.type === 'Identifier') {

Check failure on line 24 in src/babel-plugin.js

View workflow job for this annotation

GitHub Actions / Linting

Replace `assignment.type·===·'VariableDeclarator'·&&·assignment.id.type·===·'Identifier'` with `⏎············assignment.type·===·'VariableDeclarator'·&&⏎············assignment.id.type·===·'Identifier'⏎··········`
assignmentName = t.stringLiteral(rootName + ':' + assignment.id.name);

Check failure on line 25 in src/babel-plugin.js

View workflow job for this annotation

GitHub Actions / Linting

Replace `rootName·+·':'·+·assignment.id.name` with `⏎··············rootName·+·':'·+·assignment.id.name,⏎············`
}
if (assignment.type === 'ExportDefaultDeclaration') {
assignmentName = t.stringLiteral(rootName);
}

params.length = 0;
params.push(t.identifier('undefined'), assignmentName);
}
}

Check failure on line 34 in src/babel-plugin.js

View workflow job for this annotation

GitHub Actions / Linting

Insert `,`
}

Check failure on line 35 in src/babel-plugin.js

View workflow job for this annotation

GitHub Actions / Linting

Insert `,`
}

Check failure on line 36 in src/babel-plugin.js

View workflow job for this annotation

GitHub Actions / Linting

Insert `;`
}
1 change: 1 addition & 0 deletions tests/integration/gjs-test.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module('tests/integration/components/gjs', function (hooks) {
);

assert.equal(this.element.textContent.trim(), 'Hello, world!');
assert.equal(Foo.name, 'gjs-test:Foo');
});

test('it works with imports', async function (assert) {
Expand Down

0 comments on commit a776d1d

Please sign in to comment.