mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1114962 - Update the in-tree copies of acorn and pretty-fast. r=past
acorn is now at db59bd0296c16796a07e82d2dc284861f464603e (untagged commit after 0.11.0 release). pretty-fast is now at abc8c1133cc5443fb3bb50c426731821d27300a6 (tagged 0.2.0).
This commit is contained in:
parent
a2518ebb64
commit
aa514a48b8
@ -15,28 +15,38 @@ function test()
|
|||||||
openScratchpad(runTests);
|
openScratchpad(runTests);
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
content.location = "data:text/html;charset=utf8,test Scratchpad pretty print error goto line.";
|
content.location = "data:text/html;charset=utf8,"
|
||||||
|
+ "test Scratchpad pretty print error goto line.";
|
||||||
}
|
}
|
||||||
|
|
||||||
function testJumpToPrettyPrintError(sp, error, remark) {
|
function testJumpToPrettyPrintError(sp, error, remark) {
|
||||||
info("will test jumpToLine after prettyPrint error" + remark);
|
info("will test jumpToLine after prettyPrint error" + remark);
|
||||||
// CodeMirror lines and columns are 0-based, Scratchpad UI and error
|
|
||||||
// stack are 1-based.
|
// CodeMirror lines and columns are 0-based, Scratchpad UI and error
|
||||||
is(/Invalid regexp flag \(3:10\)/.test(error), true, "prettyPrint expects error in editor text:\n" + error);
|
// stack are 1-based.
|
||||||
const errorLine = 3, errorColumn = 10;
|
is(/Invalid regular expression flag \(3:10\)/.test(error), true,
|
||||||
const editorDoc = sp.editor.container.contentDocument;
|
"prettyPrint expects error in editor text:\n" + error);
|
||||||
sp.editor.jumpToLine();
|
|
||||||
const lineInput = editorDoc.querySelector("input");
|
sp.editor.jumpToLine();
|
||||||
const errorLocation = lineInput.value;
|
|
||||||
const [ inputLine, inputColumn ] = errorLocation.split(":");
|
const editorDoc = sp.editor.container.contentDocument;
|
||||||
is(inputLine, errorLine, "jumpToLine input field is set from editor selection (line)");
|
const lineInput = editorDoc.querySelector("input");
|
||||||
is(inputColumn, errorColumn, "jumpToLine input field is set from editor selection (column)");
|
const errorLocation = lineInput.value;
|
||||||
EventUtils.synthesizeKey("VK_RETURN", { }, editorDoc.defaultView);
|
const [ inputLine, inputColumn ] = errorLocation.split(":");
|
||||||
// CodeMirror lines and columns are 0-based, Scratchpad UI and error
|
const errorLine = 3, errorColumn = 10;
|
||||||
// stack are 1-based.
|
|
||||||
const cursor = sp.editor.getCursor();
|
is(inputLine, errorLine,
|
||||||
is(inputLine, cursor.line + 1, "jumpToLine goto error location (line)");
|
"jumpToLine input field is set from editor selection (line)");
|
||||||
is(inputColumn, cursor.ch + 1, "jumpToLine goto error location (column)");
|
is(inputColumn, errorColumn,
|
||||||
|
"jumpToLine input field is set from editor selection (column)");
|
||||||
|
|
||||||
|
EventUtils.synthesizeKey("VK_RETURN", { }, editorDoc.defaultView);
|
||||||
|
|
||||||
|
// CodeMirror lines and columns are 0-based, Scratchpad UI and error
|
||||||
|
// stack are 1-based.
|
||||||
|
const cursor = sp.editor.getCursor();
|
||||||
|
is(inputLine, cursor.line + 1, "jumpToLine goto error location (line)");
|
||||||
|
is(inputColumn, cursor.ch + 1, "jumpToLine goto error location (column)");
|
||||||
}
|
}
|
||||||
|
|
||||||
function runTests(sw, sp)
|
function runTests(sw, sp)
|
||||||
@ -49,12 +59,14 @@ function runTests(sw, sp)
|
|||||||
"// line 5",
|
"// line 5",
|
||||||
""
|
""
|
||||||
].join("\n"));
|
].join("\n"));
|
||||||
|
|
||||||
sp.prettyPrint().then(aFulfill => {
|
sp.prettyPrint().then(aFulfill => {
|
||||||
ok(false, "Expecting Invalid regexp flag (3:10)");
|
ok(false, "Expecting Invalid regexp flag (3:10)");
|
||||||
finish();
|
finish();
|
||||||
}, error => {
|
}, error => {
|
||||||
testJumpToPrettyPrintError(sp, error, " (Bug 1005471, first time)");
|
testJumpToPrettyPrintError(sp, error, " (Bug 1005471, first time)");
|
||||||
});
|
});
|
||||||
|
|
||||||
sp.prettyPrint().then(aFulfill => {
|
sp.prettyPrint().then(aFulfill => {
|
||||||
ok(false, "Expecting Invalid regexp flag (3:10)");
|
ok(false, "Expecting Invalid regexp flag (3:10)");
|
||||||
finish();
|
finish();
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -32,6 +32,23 @@
|
|||||||
c(node, state);
|
c(node, state);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// An ancestor walk builds up an array of ancestor nodes (including
|
||||||
|
// the current node) and passes them to the callback as the state parameter.
|
||||||
|
exports.ancestor = function(node, visitors, base, state) {
|
||||||
|
if (!base) base = exports.base;
|
||||||
|
if (!state) state = [];
|
||||||
|
function c(node, st, override) {
|
||||||
|
var type = override || node.type, found = visitors[type];
|
||||||
|
if (node != st[st.length - 1]) {
|
||||||
|
st = st.slice();
|
||||||
|
st.push(node);
|
||||||
|
}
|
||||||
|
base[type](node, st, c);
|
||||||
|
if (found) found(node, st);
|
||||||
|
}
|
||||||
|
c(node, state);
|
||||||
|
};
|
||||||
|
|
||||||
// A recursive walk is one where your functions override the default
|
// A recursive walk is one where your functions override the default
|
||||||
// walkers. They can modify and replace the state parameter that's
|
// walkers. They can modify and replace the state parameter that's
|
||||||
// threaded through the walk, and can opt how and whether to walk
|
// threaded through the walk, and can opt how and whether to walk
|
||||||
@ -180,10 +197,10 @@
|
|||||||
c(cs.consequent[j], st, "Statement");
|
c(cs.consequent[j], st, "Statement");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
base.ReturnStatement = function(node, st, c) {
|
base.ReturnStatement = base.YieldExpression = function(node, st, c) {
|
||||||
if (node.argument) c(node.argument, st, "Expression");
|
if (node.argument) c(node.argument, st, "Expression");
|
||||||
};
|
};
|
||||||
base.ThrowStatement = function(node, st, c) {
|
base.ThrowStatement = base.SpreadElement = function(node, st, c) {
|
||||||
c(node.argument, st, "Expression");
|
c(node.argument, st, "Expression");
|
||||||
};
|
};
|
||||||
base.TryStatement = function(node, st, c) {
|
base.TryStatement = function(node, st, c) {
|
||||||
@ -202,7 +219,7 @@
|
|||||||
if (node.update) c(node.update, st, "Expression");
|
if (node.update) c(node.update, st, "Expression");
|
||||||
c(node.body, st, "Statement");
|
c(node.body, st, "Statement");
|
||||||
};
|
};
|
||||||
base.ForInStatement = function(node, st, c) {
|
base.ForInStatement = base.ForOfStatement = function(node, st, c) {
|
||||||
c(node.left, st, "ForInit");
|
c(node.left, st, "ForInit");
|
||||||
c(node.right, st, "Expression");
|
c(node.right, st, "Expression");
|
||||||
c(node.body, st, "Statement");
|
c(node.body, st, "Statement");
|
||||||
@ -240,10 +257,10 @@
|
|||||||
};
|
};
|
||||||
base.ObjectExpression = function(node, st, c) {
|
base.ObjectExpression = function(node, st, c) {
|
||||||
for (var i = 0; i < node.properties.length; ++i)
|
for (var i = 0; i < node.properties.length; ++i)
|
||||||
c(node.properties[i].value, st, "Expression");
|
c(node.properties[i], st);
|
||||||
};
|
};
|
||||||
base.FunctionExpression = base.FunctionDeclaration;
|
base.FunctionExpression = base.ArrowFunctionExpression = base.FunctionDeclaration;
|
||||||
base.SequenceExpression = function(node, st, c) {
|
base.SequenceExpression = base.TemplateLiteral = function(node, st, c) {
|
||||||
for (var i = 0; i < node.expressions.length; ++i)
|
for (var i = 0; i < node.expressions.length; ++i)
|
||||||
c(node.expressions[i], st, "Expression");
|
c(node.expressions[i], st, "Expression");
|
||||||
};
|
};
|
||||||
@ -268,7 +285,28 @@
|
|||||||
c(node.object, st, "Expression");
|
c(node.object, st, "Expression");
|
||||||
if (node.computed) c(node.property, st, "Expression");
|
if (node.computed) c(node.property, st, "Expression");
|
||||||
};
|
};
|
||||||
base.Identifier = base.Literal = ignore;
|
base.Identifier = base.Literal = base.ExportDeclaration = base.ImportDeclaration = ignore;
|
||||||
|
|
||||||
|
base.TaggedTemplateExpression = function(node, st, c) {
|
||||||
|
c(node.tag, st, "Expression");
|
||||||
|
c(node.quasi, st);
|
||||||
|
};
|
||||||
|
base.ClassDeclaration = base.ClassExpression = function(node, st, c) {
|
||||||
|
if (node.superClass) c(node.superClass, st, "Expression");
|
||||||
|
for (var i = 0; i < node.body.body.length; i++)
|
||||||
|
c(node.body.body[i], st);
|
||||||
|
};
|
||||||
|
base.MethodDefinition = base.Property = function(node, st, c) {
|
||||||
|
if (node.computed) c(node.key, st, "Expression");
|
||||||
|
c(node.value, st, "Expression");
|
||||||
|
};
|
||||||
|
base.ComprehensionExpression = function(node, st, c) {
|
||||||
|
for (var i = 0; i < node.blocks.length; i++)
|
||||||
|
c(node.blocks[i].right, st, "Expression");
|
||||||
|
c(node.body, st, "Expression");
|
||||||
|
};
|
||||||
|
|
||||||
|
// NOTE: the stuff below is deprecated, and will be removed when 1.0 is released
|
||||||
|
|
||||||
// A custom walker that keeps track of the scope chain and the
|
// A custom walker that keeps track of the scope chain and the
|
||||||
// variables defined in it.
|
// variables defined in it.
|
||||||
|
@ -5,9 +5,11 @@
|
|||||||
* http://opensource.org/licenses/BSD-2-Clause
|
* http://opensource.org/licenses/BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
(function (root, factory) {
|
(function (root, factory) {
|
||||||
if (typeof define === 'function' && define.amd) {
|
"use strict";
|
||||||
|
|
||||||
|
if (typeof define === "function" && define.amd) {
|
||||||
define(factory);
|
define(factory);
|
||||||
} else if (typeof exports === 'object') {
|
} else if (typeof exports === "object") {
|
||||||
module.exports = factory();
|
module.exports = factory();
|
||||||
} else {
|
} else {
|
||||||
root.prettyFast = factory();
|
root.prettyFast = factory();
|
||||||
@ -92,7 +94,9 @@
|
|||||||
if (lastToken.type.isAssign) {
|
if (lastToken.type.isAssign) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return !!PRE_ARRAY_LITERAL_TOKENS[lastToken.type.keyword || lastToken.type.type];
|
return !!PRE_ARRAY_LITERAL_TOKENS[
|
||||||
|
lastToken.type.keyword || lastToken.type.type
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// If any of these tokens are followed by a token on a new line, we know that
|
// If any of these tokens are followed by a token on a new line, we know that
|
||||||
@ -209,7 +213,9 @@
|
|||||||
if (token.startLoc.line === lastToken.startLoc.line) {
|
if (token.startLoc.line === lastToken.startLoc.line) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (PREVENT_ASI_AFTER_TOKENS[lastToken.type.type || lastToken.type.keyword]) {
|
if (PREVENT_ASI_AFTER_TOKENS[
|
||||||
|
lastToken.type.type || lastToken.type.keyword
|
||||||
|
]) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (PREVENT_ASI_BEFORE_TOKENS[token.type.type || token.type.keyword]) {
|
if (PREVENT_ASI_BEFORE_TOKENS[token.type.type || token.type.keyword]) {
|
||||||
@ -490,8 +496,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make sure that we output the escaped character combination inside string literals
|
* Make sure that we output the escaped character combination inside string
|
||||||
* instead of various problematic characters.
|
* literals instead of various problematic characters.
|
||||||
*/
|
*/
|
||||||
var sanitize = (function () {
|
var sanitize = (function () {
|
||||||
var escapeCharacters = {
|
var escapeCharacters = {
|
||||||
@ -520,11 +526,11 @@
|
|||||||
+ ")";
|
+ ")";
|
||||||
var escapeCharactersRegExp = new RegExp(regExpString, "g");
|
var escapeCharactersRegExp = new RegExp(regExpString, "g");
|
||||||
|
|
||||||
return function(str) {
|
return function (str) {
|
||||||
return str.replace(escapeCharactersRegExp, function (_, c) {
|
return str.replace(escapeCharactersRegExp, function (_, c) {
|
||||||
return escapeCharacters[c];
|
return escapeCharacters[c];
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
}());
|
}());
|
||||||
/**
|
/**
|
||||||
* Add the given token to the pretty printed results.
|
* Add the given token to the pretty printed results.
|
||||||
@ -533,14 +539,16 @@
|
|||||||
* The token to add.
|
* The token to add.
|
||||||
* @param Function write
|
* @param Function write
|
||||||
* The function to write pretty printed code to the result SourceNode.
|
* The function to write pretty printed code to the result SourceNode.
|
||||||
* @param Object options
|
|
||||||
* The options object.
|
|
||||||
*/
|
*/
|
||||||
function addToken(token, write, options) {
|
function addToken(token, write) {
|
||||||
if (token.type.type == "string") {
|
if (token.type.type == "string") {
|
||||||
write("'" + sanitize(token.value) + "'",
|
write("'" + sanitize(token.value) + "'",
|
||||||
token.startLoc.line,
|
token.startLoc.line,
|
||||||
token.startLoc.column);
|
token.startLoc.column);
|
||||||
|
} else if (token.type.type == "regexp") {
|
||||||
|
write(String(token.value.value),
|
||||||
|
token.startLoc.line,
|
||||||
|
token.startLoc.column);
|
||||||
} else {
|
} else {
|
||||||
write(String(token.value != null ? token.value : token.type.type),
|
write(String(token.value != null ? token.value : token.type.type),
|
||||||
token.startLoc.line,
|
token.startLoc.line,
|
||||||
@ -584,7 +592,7 @@
|
|||||||
*/
|
*/
|
||||||
function decrementsIndent(tokenType, stack) {
|
function decrementsIndent(tokenType, stack) {
|
||||||
return tokenType == "}"
|
return tokenType == "}"
|
||||||
|| (tokenType == "]" && stack[stack.length - 1] == "[\n")
|
|| (tokenType == "]" && stack[stack.length - 1] == "[\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -690,12 +698,13 @@
|
|||||||
for (var i = 0, len = buffer.length; i < len; i++) {
|
for (var i = 0, len = buffer.length; i < len; i++) {
|
||||||
lineStr += buffer[i];
|
lineStr += buffer[i];
|
||||||
}
|
}
|
||||||
result.add(new SourceNode(bufferLine, bufferColumn, options.url, lineStr));
|
result.add(new SourceNode(bufferLine, bufferColumn, options.url,
|
||||||
|
lineStr));
|
||||||
buffer.splice(0, buffer.length);
|
buffer.splice(0, buffer.length);
|
||||||
bufferLine = -1;
|
bufferLine = -1;
|
||||||
bufferColumn = -1;
|
bufferColumn = -1;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}());
|
}());
|
||||||
|
|
||||||
// Whether or not we added a newline on after we added the last token.
|
// Whether or not we added a newline on after we added the last token.
|
||||||
@ -773,7 +782,7 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
while (true) {
|
for (;;) {
|
||||||
token = getToken();
|
token = getToken();
|
||||||
|
|
||||||
ttk = token.type.keyword;
|
ttk = token.type.keyword;
|
||||||
@ -807,8 +816,8 @@
|
|||||||
|
|
||||||
prependWhiteSpace(token, lastToken, addedNewline, write, options,
|
prependWhiteSpace(token, lastToken, addedNewline, write, options,
|
||||||
indentLevel, stack);
|
indentLevel, stack);
|
||||||
addToken(token, write, options);
|
addToken(token, write);
|
||||||
if (commentQueue.length == 0 || !commentQueue[0].trailing) {
|
if (commentQueue.length === 0 || !commentQueue[0].trailing) {
|
||||||
addedNewline = appendNewline(token, write, stack);
|
addedNewline = appendNewline(token, write, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* -*- indent-tabs-mode: nil; js-indent-level: 2; fill-column: 80 -*- */
|
/* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2; fill-column: 80 -*- */
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user