-
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add template only name #58
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import type { EmberTemplateCompiler, PreprocessOptions } from './ember-template- | |
import { LegacyModuleName } from './public-types'; | ||
import { ScopeLocals } from './scope-locals'; | ||
import { ASTPluginBuilder, preprocess, print } from '@glimmer/syntax'; | ||
import { basename, extname } from 'path'; | ||
|
||
export * from './public-types'; | ||
|
||
|
@@ -496,14 +497,27 @@ function insertCompiledTemplate<EnvSpecificOptions>( | |
|
||
let expression = t.callExpression(templateFactoryIdentifier, [templateExpression]); | ||
|
||
let assignment = target.parent; | ||
let assignmentName: t.StringLiteral = t.stringLiteral(state.filename); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can leak whole filesystem paths, which is both bloat and information leak. Also, it's not even a good answer, because you can have many components in this same file and they will all look as if they're the same component in the inspector, leading to confusion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right, should be the same as below, babel.types.identifier('undefined') |
||
if (assignment.type === 'AssignmentExpression' && assignment.left.type === 'Identifier') { | ||
assignmentName = t.stringLiteral(assignment.left.name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using local variables like this is also likely to mislead, because nothing is stopping people from reusing the same local variable names in different modules that interact with each other. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think its the best we can do right now. at least better than unknown template. |
||
} | ||
if (assignment.type === 'VariableDeclarator' && assignment.id.type === 'Identifier') { | ||
assignmentName = t.stringLiteral(assignment.id.name); | ||
} | ||
if (assignment.type === 'ExportDefaultDeclaration') { | ||
const name = basename(state.filename).slice(0, -extname(state.filename).length); | ||
assignmentName = t.stringLiteral(name); | ||
} | ||
|
||
if (config.rfc931Support) { | ||
expression = t.callExpression(i.import('@ember/component', 'setComponentTemplate'), [ | ||
expression, | ||
backingClass?.node ?? | ||
t.callExpression( | ||
i.import('@ember/component/template-only', 'default', 'templateOnly'), | ||
[] | ||
), | ||
t.callExpression(i.import('@ember/component/template-only', 'default', 'templateOnly'), [ | ||
t.identifier('undefined'), | ||
assignmentName, | ||
]), | ||
]); | ||
} | ||
return expression; | ||
|
@@ -606,14 +620,29 @@ function updateCallForm<EnvSpecificOptions>( | |
convertStrictMode(babel, target); | ||
removeEvalAndScope(target); | ||
target.node.arguments = target.node.arguments.slice(0, 2); | ||
|
||
let assignment = target.parent; | ||
let assignmentName: Babel.types.Identifier | Babel.types.StringLiteral = | ||
babel.types.identifier('undefined'); | ||
if (assignment.type === 'AssignmentExpression' && assignment.left.type === 'Identifier') { | ||
assignmentName = babel.types.stringLiteral(assignment.left.name); | ||
} | ||
if (assignment.type === 'VariableDeclarator' && assignment.id.type === 'Identifier') { | ||
assignmentName = babel.types.stringLiteral(assignment.id.name); | ||
} | ||
if (assignment.type === 'ExportDefaultDeclaration') { | ||
const name = basename(state.filename).slice(0, -extname(state.filename).length); | ||
assignmentName = babel.types.stringLiteral(name); | ||
} | ||
|
||
state.recursionGuard.add(target.node); | ||
state.util.replaceWith(target, (i) => | ||
babel.types.callExpression(i.import('@ember/component', 'setComponentTemplate'), [ | ||
target.node, | ||
backingClass?.node ?? | ||
babel.types.callExpression( | ||
i.import('@ember/component/template-only', 'default', 'templateOnly'), | ||
[] | ||
[babel.types.identifier('undefined'), assignmentName] | ||
), | ||
]) | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be PascalCase, since it's what would get shown in the inspector, and how it would be invoked by a consumer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inspector would auto transform it to pascal case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inspector:

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it also doesn't matter if it starts with lower case. so
my-template-only-2
would also be shown asMyTemplateOnly2