diff --git a/source/parser.hera b/source/parser.hera index 747dfd0a..4513f34c 100644 --- a/source/parser.hera +++ b/source/parser.hera @@ -6255,8 +6255,8 @@ Shebang /#![^\r\n]*/ EOL CivetPrologue - [\t ]* DoubleQuote CivetPrologueContent:content DoubleQuote $SimpleStatementDelimiter EOS? -> content - [\t ]* SingleQuote CivetPrologueContent:content SingleQuote $SimpleStatementDelimiter EOS? -> content + [\t ]* DoubleQuote CivetPrologueContent:content DoubleQuote SimpleStatementDelimiter EOS? -> content + [\t ]* SingleQuote CivetPrologueContent:content SingleQuote SimpleStatementDelimiter EOS? -> content CivetPrologueContent "civet" NonIdContinue CivetOption*:options [\s]* -> @@ -6290,7 +6290,14 @@ UnknownPrologue # Can't use $EOS because it will prevent re-writing of coffee style comments [\t ]* StringLiteral:s $SimpleStatementDelimiter EOS +TripleSlashDirective + # https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html + /\/\/\/[^\r\n]*/ EOS? + DirectivePrologue + PrologueString + +PrologueString CivetPrologue UnknownPrologue @@ -6726,7 +6733,7 @@ Reset } Init - Shebang? DirectivePrologue*:directives "" -> + Shebang? TripleSlashDirective* DirectivePrologue*:directives -> directives.forEach((directive) => { if (directive.type === "CivetPrologue") { Object.assign(module.config, directive.config) diff --git a/test/prologues.civet b/test/prologues.civet new file mode 100644 index 00000000..b6d701a7 --- /dev/null +++ b/test/prologues.civet @@ -0,0 +1,21 @@ +{testCase} from ./helper.civet + +describe "shebang", -> + testCase """ + keeps it at the top + --- + #! /usr/bin/env node + --- + #! /usr/bin/env node + """ + +describe "Triple Slash directives", -> + testCase """ + https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html + --- + /// + x = 1 + --- + /// + x = 1 + """ diff --git a/test/regex.civet b/test/regex.civet index 2420c89d..c10ab613 100644 --- a/test/regex.civet +++ b/test/regex.civet @@ -76,162 +76,199 @@ describe "regexp", -> Math.floor(x / y) // comment """ + // NOTE: Need the ';' so that the heregex isn't interperted as a https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html describe "heregex", -> testCase """ basic --- + ; ///abc/// --- + ; /abc/ """ testCase """ flags --- + ; ///abc///g --- + ; /abc/g """ testCase """ escapes --- + ; ///\\u200C/// --- + ; /\\u200C/ """ testCase """ strips whitespace --- + ; /// abc /// --- + ; /abc/ """ testCase """ escapes single slashes --- + ; /// / /// --- + ; /\\// """ testCase """ escaped space --- + ; ///\\ /// --- + ; / / """ testCase """ escaped newline --- + ; ///\\\n/// --- + ; /\\n/ """ testCase """ space in character class --- + ; ///[ ]/// --- + ; /[ ]/ """ testCase """ comment in character class --- + ; ///[/*]/// --- + ; /[/*]/ """ testCase """ coffee comment in character class --- + ; ///[ # hey ]/// --- + ; /[ # hey ]/ """ testCase """ triple slash inside character class --- + ; ///a[///]/// --- + ; /a[///]/ """ testCase """ JS comment --- + ; /// abb // hey /// --- + ; /abb/ """ testCase ''' substitutions --- + ; ///#{a}/// --- + ; RegExp(`${a}`) ''' testCase ''' substitutions escape backticks --- + ; /// `#{a} /// --- + ; RegExp(`\\`${a}`) ''' testCase ''' allows both kinds of substitutions --- + ; /// ${yo} $ { x } #{a} /// --- + ; RegExp(`${yo}\\${x}${a}`) ''' testCase ''' escaped bracket --- + ; /// \\[ /// --- + ; /\\[/ ''' testCase ''' escaped bracket with substitution --- + ; /// \\[#{a}] /// --- + ; RegExp(`\\\\[${a}]`) ''' testCase ''' substitutions keep flags --- + ; /// x#{a} ///g --- + ; RegExp(`x${a}`, "g") ''' @@ -239,6 +276,7 @@ describe "regexp", -> testCase ''' coffee script's heregex --- + ; /// ^ (?: # Match any character, except those that need special handling below. @@ -254,5 +292,6 @@ describe "regexp", -> )* /// --- + ; /^(?:[^\\\\/\\#\\s]|\\\\[\\s\\S]|\\/(?!\\/\\/)|\\#(?!\\{)|\\s+(?:\\#(?!\\{).*)?)*/ ''' diff --git a/test/shebang.civet b/test/shebang.civet deleted file mode 100644 index 57a4a1bc..00000000 --- a/test/shebang.civet +++ /dev/null @@ -1,10 +0,0 @@ -{testCase} from ./helper.civet - -describe "shebang", -> - testCase """ - keeps it at the top - --- - #! /usr/bin/env node - --- - #! /usr/bin/env node - """