[Pkg-javascript-commits] [uglifyjs] 91/190: Allow operator names as getters/setters
Antonio Terceiro
terceiro at moszumanska.debian.org
Sun Aug 7 23:17:16 UTC 2016
This is an automated email from the git hooks/post-receive script.
terceiro pushed a commit to annotated tag upstream/2.7.0
in repository uglifyjs.
commit 26641f3fb20bce9394c3989bea0099dcd209be61
Author: Anthony Van de Gejuchte <anthonyvdgent at gmail.com>
Date: Fri Jan 15 15:58:15 2016 +0100
Allow operator names as getters/setters
Fixes #919
Fix provided by @kzc
---
lib/parse.js | 7 ++++
test/compress/issue-12.js | 47 ++++++++++++++++++++++++
test/mocha/getter-setter.js | 89 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 143 insertions(+)
diff --git a/lib/parse.js b/lib/parse.js
index 2218c00..f149515 100644
--- a/lib/parse.js
+++ b/lib/parse.js
@@ -1178,6 +1178,13 @@ function parse($TEXT, options) {
break;
}
break;
+ case "operator":
+ if (!is_identifier_string(tok.value)) {
+ throw new JS_Parse_Error("Invalid getter/setter name: " + tok.value,
+ tok.file, tok.line, tok.col, tok.pos);
+ }
+ ret = _make_symbol(AST_SymbolRef);
+ break;
}
next();
return ret;
diff --git a/test/compress/issue-12.js b/test/compress/issue-12.js
index bf87d5c..e2d8bda 100644
--- a/test/compress/issue-12.js
+++ b/test/compress/issue-12.js
@@ -9,3 +9,50 @@ keep_name_of_setter: {
input: { a = { set foo () {} } }
expect: { a = { set foo () {} } }
}
+
+setter_with_operator_keys: {
+ input: {
+ var tokenCodes = {
+ get instanceof(){
+ return test0;
+ },
+ set instanceof(value){
+ test0 = value;
+ },
+ set typeof(value){
+ test1 = value;
+ },
+ get typeof(){
+ return test1;
+ },
+ set else(value){
+ test2 = value;
+ },
+ get else(){
+ return test2;
+ }
+ };
+ }
+ expect: {
+ var tokenCodes = {
+ get instanceof(){
+ return test0;
+ },
+ set instanceof(value){
+ test0 = value;
+ },
+ set typeof(value){
+ test1 = value;
+ },
+ get typeof(){
+ return test1;
+ },
+ set else(value){
+ test2 = value;
+ },
+ get else(){
+ return test2;
+ }
+ };
+ }
+}
\ No newline at end of file
diff --git a/test/mocha/getter-setter.js b/test/mocha/getter-setter.js
new file mode 100644
index 0000000..641a202
--- /dev/null
+++ b/test/mocha/getter-setter.js
@@ -0,0 +1,89 @@
+var UglifyJS = require('../../');
+var assert = require("assert");
+
+describe("Getters and setters", function() {
+ it("Should not accept operator symbols as getter/setter name", function() {
+ var illegalOperators = [
+ "++",
+ "--",
+ "+",
+ "-",
+ "!",
+ "~",
+ "&",
+ "|",
+ "^",
+ "*",
+ "/",
+ "%",
+ ">>",
+ "<<",
+ ">>>",
+ "<",
+ ">",
+ "<=",
+ ">=",
+ "==",
+ "===",
+ "!=",
+ "!==",
+ "?",
+ "=",
+ "+=",
+ "-=",
+ "/=",
+ "*=",
+ "%=",
+ ">>=",
+ "<<=",
+ ">>>=",
+ "|=",
+ "^=",
+ "&=",
+ "&&",
+ "||"
+ ];
+ var generator = function() {
+ var results = [];
+
+ for (var i in illegalOperators) {
+ results.push({
+ code: "var obj = { get " + illegalOperators[i] + "() { return test; }};",
+ operator: illegalOperators[i],
+ method: "get"
+ });
+ results.push({
+ code: "var obj = { set " + illegalOperators[i] + "(value) { test = value}};",
+ operator: illegalOperators[i],
+ method: "set"
+ });
+ }
+
+ return results;
+ };
+
+ var testCase = function(data) {
+ return function() {
+ UglifyJS.parse(data.code);
+ };
+ };
+
+ var fail = function(data) {
+ return function (e) {
+ return e instanceof UglifyJS.JS_Parse_Error &&
+ e.message === "Invalid getter/setter name: " + data.operator;
+ };
+ };
+
+ var errorMessage = function(data) {
+ return "Expected but didn't get a syntax error while parsing following line:\n" + data.code;
+ };
+
+ var tests = generator();
+ for (var i = 0; i < tests.length; i++) {
+ var test = tests[i];
+ assert.throws(testCase(test), fail(test), errorMessage(test));
+ }
+ });
+
+});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git
More information about the Pkg-javascript-commits
mailing list