-
Notifications
You must be signed in to change notification settings - Fork 462
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 tests for Hashbang comments #1983
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/*--- | ||
esid: pending | ||
description: > | ||
Hashbang comments should be available in Script evaluator contexts. | ||
info: | | ||
HashbangComment:: | ||
#! SingleLineCommentChars[opt] | ||
---*/ | ||
|
||
assert.sameValue(eval('#!\n'), undefined); | ||
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. add here assertions to assert they are only available at the beginning? assert.throws(SyntaxError, () => eval(' #!\n'), 'whitespace');
assert.throws(SyntaxError, () => eval('\n#!\n'), 'new line'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/*--- | ||
esid: pending | ||
description: > | ||
Hashbang comments should not be allowed in function evaluator contexts. | ||
info: | | ||
HashbangComment:: | ||
#! SingleLineCommentChars[opt] | ||
flags: [module] | ||
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. remove? |
||
---*/ | ||
const AsyncFunction = (async function (){}).constructor; | ||
const GeneratorFunction = (function *(){}).constructor; | ||
const AsyncGeneratorFunction = (async function *(){}).constructor; | ||
for (ctor of [ | ||
Function, | ||
AsyncFunction, | ||
GeneratorFunction, | ||
AsyncGeneratorFunction, | ||
]) { | ||
assert.throws(SyntaxError, () => ctor('#!\n_',''), `${ctor.name} Call argument`); | ||
assert.throws(SyntaxError, () => ctor('#!\n_'), `${ctor.name} Call body`); | ||
assert.throws(SyntaxError, () => new ctor('#!\n_',''), `${ctor.name} Construct argument`); | ||
assert.throws(SyntaxError, () => new ctor('#!\n_'), `${ctor.name} Construct body`); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#! | ||
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. add other test files verifying these characters can't be escaped? one for 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. Let’s try multiple types of escapes: https://github.com/v8/v8/blob/effb7ad728cf13da143fae41b03b0525f4ff65d5/test/cctest/test-parsing.cc#L11446-L11455 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. cool! I'll work on some follow ups for this PR and this is a good material |
||
/*--- | ||
esid: pending | ||
description: > | ||
Hashbang comments should be allowed in Modules. | ||
info: | | ||
HashbangComment:: | ||
#! SingleLineCommentChars[opt] | ||
flags: [module] | ||
---*/ | ||
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. please add the |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/* | ||
these characters should not be considered within a comment | ||
*/ | ||
/*--- | ||
esid: pending | ||
description: > | ||
Hashbang comments should not interpret multi-line comments. | ||
info: | | ||
HashbangComment:: | ||
#! SingleLineCommentChars[opt] | ||
flags: [raw] | ||
negative: | ||
phase: parse | ||
type: SyntaxError | ||
---*/ | ||
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. lol, this test is so fun! please add the |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/*--- | ||
esid: pending | ||
description: > | ||
Hashbang comments should not require a newline afterwards | ||
info: | | ||
HashbangComment:: | ||
#! SingleLineCommentChars[opt] | ||
flags: [raw] | ||
---*/ | ||
|
||
eval('#!'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#! these characters should be treated as a comment | ||
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 definitely need to change the linter to not fail for this. I believe it will say you're missing the copyright lines here... |
||
/*--- | ||
esid: pending | ||
description: > | ||
Hashbang comments should be allowed in Scripts and should not be required to be empty. | ||
info: | | ||
HashbangComment:: | ||
#! SingleLineCommentChars[opt] | ||
flags: [raw] | ||
---*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"use strict" | ||
#! | ||
/*--- | ||
esid: pending | ||
description: > | ||
Hashbang comments should only be allowed at start of source texts and should not be preceded by DirectivePrologues. | ||
info: | | ||
HashbangComment:: | ||
#! SingleLineCommentChars[opt] | ||
flags: [raw] | ||
negative: | ||
phase: parse | ||
type: SyntaxError | ||
---*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
;#! | ||
/*--- | ||
esid: pending | ||
description: > | ||
Hashbang comments should only be allowed at the start of source texts and should not be preceded by empty statements. | ||
info: | | ||
HashbangComment:: | ||
#! SingleLineCommentChars[opt] | ||
flags: [raw] | ||
negative: | ||
phase: parse | ||
type: SyntaxError | ||
---*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#! | ||
#! | ||
/*--- | ||
esid: pending | ||
description: > | ||
Hashbang comments should only be allowed at the start of source texts and should not be preceded by Hashbang comments. | ||
info: | | ||
HashbangComment:: | ||
#! SingleLineCommentChars[opt] | ||
flags: [raw] | ||
negative: | ||
phase: parse | ||
type: SyntaxError | ||
---*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
#! | ||
/*--- | ||
esid: pending | ||
description: > | ||
Hashbang comments should only be allowed at the start of source texts and should not be preceded by line comments. | ||
info: | | ||
HashbangComment:: | ||
#! SingleLineCommentChars[opt] | ||
flags: [raw] | ||
negative: | ||
phase: parse | ||
type: SyntaxError | ||
---*/ | ||
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. same case of raw mode, please add this to the other files accordingly. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
*/#! | ||
/*--- | ||
esid: pending | ||
description: > | ||
Hashbang comments should only be allowed at the start of source texts and should not be preceded by multi-line comments. | ||
info: | | ||
HashbangComment:: | ||
#! SingleLineCommentChars[opt] | ||
flags: [raw] | ||
negative: | ||
phase: parse | ||
type: SyntaxError | ||
---*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#! | ||
/*--- | ||
esid: pending | ||
description: > | ||
Hashbang comments should only be allowed at the start of source texts and should not be preceded by whitespace. | ||
info: | | ||
HashbangComment:: | ||
#! SingleLineCommentChars[opt] | ||
flags: [raw] | ||
negative: | ||
phase: parse | ||
type: SyntaxError | ||
---*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/*--- | ||
esid: pending | ||
description: > | ||
Hashbang comments should only be allowed at the start of source texts and should not be allowed within blocks. | ||
info: | | ||
HashbangComment:: | ||
#! SingleLineCommentChars[opt] | ||
flags: [raw] | ||
negative: | ||
phase: parse | ||
type: SyntaxError | ||
---*/ | ||
{ | ||
#! | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,12 @@ | ||||||
#!"use strict" | ||||||
/*--- | ||||||
esid: pending | ||||||
description: > | ||||||
Hashbang comments should not be interpretted and should not generate DirectivePrologues. | ||||||
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.
Suggested change
|
||||||
info: | | ||||||
HashbangComment:: | ||||||
#! SingleLineCommentChars[opt] | ||||||
flags: [raw] | ||||||
---*/ | ||||||
|
||||||
with ({}) {} |
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 wish I didn't have to say that, but we need to have the 2 lines of copyright on each test file.
I'm sorry this is a thing we'd need to get fixed in a meeting. Thanks for understanding.
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 hate this requirement, btw.
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.
is it fine to have them below the
#!
?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.
sure! I only need to "fix" the linter