[Pkg-javascript-commits] [node-acorn-jsx] 25/484: Accept \0 in strings in strict mode
Bastien Roucariès
rouca at moszumanska.debian.org
Sat Aug 19 14:19:59 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-acorn-jsx.
commit 0590d1224028eb0b8abe320cca35f38385297a02
Author: Marijn Haverbeke <marijnh at gmail.com>
Date: Wed Oct 3 22:18:52 2012 +0200
Accept \0 in strings in strict mode
Closes #3
---
acorn.js | 1 +
index.html | 3 +-
test/tests.js | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 148 insertions(+), 1 deletion(-)
diff --git a/acorn.js b/acorn.js
index a29d11f..0f04af0 100644
--- a/acorn.js
+++ b/acorn.js
@@ -660,6 +660,7 @@
var octal = /^[0-7]+/.exec(input.slice(tokPos, tokPos + 3));
if (octal) octal = octal[0];
while (octal && parseInt(octal, 8) > 255) octal = octal.slice(0, octal.length - 1);
+ if (octal === "0") octal = null;
++tokPos;
if (octal) {
if (strict) raise(tokPos - 2, "Octal literal in strict mode");
diff --git a/index.html b/index.html
index 132399d..31df065 100644
--- a/index.html
+++ b/index.html
@@ -187,7 +187,7 @@ code point above 128.</p> </td> <td class="code">
<span class="kd">var</span> <span class="nx">nonASCIIidentifierChars</span> <span class="o">=</span> <span class="s2">"\u0371-\u0374\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u0620-\u0649\u0672-\u06d3\u06e7-\u06e8\u06fb-\u06fc\u0730-\u074a\u0800-\u0814\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0840-\u0857\u08e4-\u08fe\u0900-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962-\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09d7\u09df- [...]
<span class="kd">var</span> <span class="nx">nonASCIIidentifierStart</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">RegExp</span><span class="p">(</span><span class="s2">"["</span> <span class="o">+</span> <span class="nx">nonASCIIidentifierStartChars</span> <span class="o">+</span> <span class="s2">"]"</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">nonASCIIidentifier</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">RegExp</span><span class="p">(</span><span class="s2">"["</span> <span class="o">+</span> <span class="nx">nonASCIIidentifierStartChars</span> <span class="o">+</span> <span class="nx">nonASCIIidentifierChars</span> <span class="o">+</span> <span class="s2">"]"</span><span class="p">);</span></pre></div> </td> [...]
-line break). Used to count lines.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">lineBreak</span> <span class="o">=</span> <span class="sr">/\r\n?|[\n\r\u2028\u2029]/g</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-44"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" h [...]
+line break). Used to count lines.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">lineBreak</span> <span class="o">=</span> <span class="sr">/\r\n|[\n\r\u2028\u2029]/g</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-44"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" hr [...]
<span class="k">return</span> <span class="p">(</span><span class="nx">code</span> <span class="o">>=</span> <span class="mi">65</span> <span class="o">&&</span> <span class="nx">code</span> <span class="o"><=</span> <span class="mi">90</span><span class="p">)</span> <span class="o">||</span> <span class="p">(</span><span class="nx">code</span> <span class="o">>=</span> <span class="mi">97</span> <span class="o">&&</span> <span class="nx">code</span> <span cl [...]
<span class="nx">code</span> <span class="o">===</span> <span class="mi">36</span> <span class="o">||</span> <span class="nx">code</span> <span class="o">===</span> <span class="mi">95</span> <span class="o">||</span>
<span class="p">(</span><span class="nx">code</span> <span class="o">>=</span> <span class="mh">0xaa</span> <span class="o">&&</span> <span class="nx">nonASCIIidentifierStart</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nb">String</span><span class="p">.</span><span class="nx">fromCharCode</span><span class="p">(</span><span class="nx">code</span><span class="p">)));</span>
@@ -438,6 +438,7 @@ will return <code>null</code> unless the integer has exactly <code>len</code> di
<span class="kd">var</span> <span class="nx">octal</span> <span class="o">=</span> <span class="sr">/^[0-7]+/</span><span class="p">.</span><span class="nx">exec</span><span class="p">(</span><span class="nx">input</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="nx">tokPos</span><span class="p">,</span> <span class="nx">tokPos</span> <span class="o">+</span> <span class="mi">3</span><span class="p">));</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">octal</span><span class="p">)</span> <span class="nx">octal</span> <span class="o">=</span> <span class="nx">octal</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span>
<span class="k">while</span> <span class="p">(</span><span class="nx">octal</span> <span class="o">&&</span> <span class="nb">parseInt</span><span class="p">(</span><span class="nx">octal</span><span class="p">,</span> <span class="mi">8</span><span class="p">)</span> <span class="o">></span> <span class="mi">255</span><span class="p">)</span> <span class="nx">octal</span> <span class="o">=</span> <span class="nx">octal</span><span class="p">.</span><span class="nx">sl [...]
+ <span class="k">if</span> <span class="p">(</span><span class="nx">octal</span> <span class="o">===</span> <span class="s2">"0"</span><span class="p">)</span> <span class="nx">octal</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
<span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">octal</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">strict</span><span class="p">)</span> <span class="nx">raise</span><span class="p">(</span><span class="nx">tokPos</span> <span class="o">-</span> <span class="mi">2</span><span class="p">,</span> <span class="s2">"Octal literal in strict mode"</span><span class="p">);</span>
diff --git a/test/tests.js b/test/tests.js
index 4dbbe7f..a34b769 100644
--- a/test/tests.js
+++ b/test/tests.js
@@ -25836,6 +25836,151 @@ test("foo: if (true) break foo;", {
]
});
+test("(function () { 'use strict'; '\0'; }())", {
+ type: "Program",
+ start: 0,
+ end: 38,
+ loc: {
+ start: {
+ line: 1,
+ column: 0
+ },
+ end: {
+ line: 1,
+ column: 38
+ }
+ },
+ body: [
+ {
+ type: "ExpressionStatement",
+ start: 0,
+ end: 38,
+ loc: {
+ start: {
+ line: 1,
+ column: 0
+ },
+ end: {
+ line: 1,
+ column: 38
+ }
+ },
+ expression: {
+ type: "CallExpression",
+ start: 1,
+ loc: {
+ start: {
+ line: 1,
+ column: 1
+ },
+ end: {
+ line: 1,
+ column: 37
+ }
+ },
+ callee: {
+ type: "FunctionExpression",
+ start: 1,
+ end: 35,
+ loc: {
+ start: {
+ line: 1,
+ column: 1
+ },
+ end: {
+ line: 1,
+ column: 35
+ }
+ },
+ id: null,
+ params: [],
+ body: {
+ type: "BlockStatement",
+ start: 13,
+ end: 35,
+ loc: {
+ start: {
+ line: 1,
+ column: 13
+ },
+ end: {
+ line: 1,
+ column: 35
+ }
+ },
+ body: [
+ {
+ type: "ExpressionStatement",
+ start: 15,
+ end: 28,
+ loc: {
+ start: {
+ line: 1,
+ column: 15
+ },
+ end: {
+ line: 1,
+ column: 28
+ }
+ },
+ expression: {
+ type: "Literal",
+ start: 15,
+ end: 27,
+ loc: {
+ start: {
+ line: 1,
+ column: 15
+ },
+ end: {
+ line: 1,
+ column: 27
+ }
+ },
+ value: "use strict"
+ }
+ },
+ {
+ type: "ExpressionStatement",
+ start: 29,
+ end: 33,
+ loc: {
+ start: {
+ line: 1,
+ column: 29
+ },
+ end: {
+ line: 1,
+ column: 33
+ }
+ },
+ expression: {
+ type: "Literal",
+ start: 29,
+ end: 32,
+ loc: {
+ start: {
+ line: 1,
+ column: 29
+ },
+ end: {
+ line: 1,
+ column: 32
+ }
+ },
+ value: "\u0000"
+ }
+ }
+ ]
+ }
+ },
+ arguments: [],
+ end: 37
+ }
+ }
+ ]
+});
+
// Failure tests
testFail("{",
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-acorn-jsx.git
More information about the Pkg-javascript-commits
mailing list