-
Notifications
You must be signed in to change notification settings - Fork 143
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
Make the helper keyword handling less strict #1150
Changes from all 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 |
---|---|---|
|
@@ -519,7 +519,7 @@ describe('compat-resolver', function () { | |
}, | ||
]); | ||
}); | ||
test('string literal passed to `helper` helper in content position', function () { | ||
test('string literal passed to "helper" keyword in content position', function () { | ||
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 started renaming "helper" to "keyword" since that's the word they use in the error in ember-source:
I assumed "keyword" was an implementation detail and not an end-user facing term, but it seems it's used in error messages so I think we can be consistent with that? 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. Yes, I agree, it seems clearer to say "keyword" |
||
let findDependencies = configure({ | ||
staticHelpers: true, | ||
}); | ||
|
@@ -584,7 +584,7 @@ describe('compat-resolver', function () { | |
) | ||
).toEqual([]); | ||
}); | ||
test('built-in helpers are ignored when used with the "helper" helper', function () { | ||
test('built-in helpers are ignored when used with the "helper" keyword', function () { | ||
let findDependencies = configure({ | ||
staticHelpers: true, | ||
}); | ||
|
@@ -714,7 +714,7 @@ describe('compat-resolver', function () { | |
}, | ||
]); | ||
}); | ||
test('string literal passed to "helper" helper in helper position', function () { | ||
test('string literal passed to "helper" keyword in helper position', function () { | ||
let findDependencies = configure({ staticHelpers: true }); | ||
givenFile('helpers/hello-world.js'); | ||
expect( | ||
|
@@ -733,6 +733,27 @@ describe('compat-resolver', function () { | |
}, | ||
]); | ||
}); | ||
test('helper currying using the "helper" keyword', function () { | ||
let findDependencies = configure({ staticHelpers: true }); | ||
givenFile('helpers/hello-world.js'); | ||
expect( | ||
findDependencies( | ||
'templates/application.hbs', | ||
` | ||
{{#let (helper "hello-world" name="World") as |hello|}} | ||
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 is based on the code snippet in the RFC. |
||
{{#let (helper hello name="Tomster") as |helloTomster|}} | ||
{{helloTomster name="Zoey"}} | ||
{{/let}} | ||
{{/let}} | ||
` | ||
) | ||
).toEqual([ | ||
{ | ||
path: '../helpers/hello-world.js', | ||
runtimeName: 'the-app/helpers/hello-world', | ||
}, | ||
]); | ||
}); | ||
test('string literal passed to "modifier" keyword in helper position', function () { | ||
let findDependencies = configure({ staticModifiers: true }); | ||
givenFile('modifiers/add-listener.js'); | ||
|
@@ -759,7 +780,7 @@ describe('compat-resolver', function () { | |
findDependencies('templates/application.hbs', `{{my-thing header=(component "hello-world") }}`); | ||
}).toThrow(new RegExp(`Missing component: hello-world in templates/application.hbs`)); | ||
}); | ||
test('string literal passed to "helper" helper fails to resolve', function () { | ||
test('string literal passed to "helper" keyword fails to resolve', function () { | ||
let findDependencies = configure({ staticHelpers: true }); | ||
expect(() => { | ||
findDependencies('templates/application.hbs', `{{helper "hello-world"}}`); | ||
|
@@ -779,8 +800,9 @@ describe('compat-resolver', function () { | |
givenFile('components/my-thing.js'); | ||
expect(findDependencies('templates/application.hbs', `{{my-thing header=(component "hello-world") }}`)).toEqual([]); | ||
}); | ||
test('string literal passed to "helper" helper fails to resolve when staticHelpers is off', function () { | ||
test('string literal passed to "helper" keyword fails to resolve when staticHelpers is off', function () { | ||
let findDependencies = configure({ staticHelpers: false }); | ||
givenFile('helpers/hello-world.js'); | ||
expect(findDependencies('templates/application.hbs', `{{helper "hello-world"}}`)).toEqual([]); | ||
}); | ||
test('string literal passed to "modifier" keyword fails to resolve when staticModifiers is off', function () { | ||
|
@@ -1854,18 +1876,9 @@ describe('compat-resolver', function () { | |
); | ||
}); | ||
|
||
test('rejects arbitrary expression in "helper" helper', function () { | ||
test('ignores any non-string-literal in "helper" keyword', function () { | ||
let findDependencies = configure({ staticHelpers: true }); | ||
expect(() => findDependencies('templates/application.hbs', `{{helper (some-helper this.which) }}`)).toThrow( | ||
`Unsafe dynamic helper: cannot statically analyze this expression` | ||
); | ||
}); | ||
|
||
test('rejects any non-string-literal in "helper" helper', function () { | ||
let findDependencies = configure({ staticHelpers: true }); | ||
expect(() => findDependencies('templates/application.hbs', `{{helper this.which }}`)).toThrow( | ||
`Unsafe dynamic helper: cannot statically analyze this expression` | ||
); | ||
expect(findDependencies('templates/application.hbs', `{{helper this.which}}`)).toEqual([]); | ||
}); | ||
|
||
test('ignores any non-string-literal in "modifier" keyword', function () { | ||
|
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.
I'm new to TypeScript but I think
Expression
is the correct type here sincenode.params
seems to be typed asExpression[]
?Expression
doesn't include theTextNode
type, so that doesn't need to be covered anymore.(I think that's also the case for the component helper version).