Merge pull request #17 from jridgewell/mallot

Support Mallet operator
This commit is contained in:
Sebastian McKenzie 2015-01-17 21:58:48 +11:00
commit 8aa74ab845
2 changed files with 81 additions and 1 deletions

View File

@ -805,7 +805,10 @@
function readToken_pipe_amp(code) { // '|&'
var next = input.charCodeAt(tokPos + 1);
if (next === code) return finishOp(code === 124 ? _logicalOR : _logicalAND, 2);
if (next === code) {
if (options.playground && input.charCodeAt(tokPos + 2) === 61) return finishOp(_assign, 3);
return finishOp(code === 124 ? _logicalOR : _logicalAND, 2);
}
if (next === 61) return finishOp(_assign, 2);
return finishOp(code === 124 ? _bitwiseOR : _bitwiseAND, 1);
}

View File

@ -245,6 +245,83 @@ test("obj.x ?= 2;", {
playground: true
});
test("x ||= 2;", {
type: "Program",
start: 0,
end: 8,
body: [{
type: "ExpressionStatement",
start: 0,
end: 8,
expression: {
type: "AssignmentExpression",
start: 0,
end: 7,
left: {
type: "Identifier",
start: 0,
end: 1
},
right: {
type: "Literal",
start: 6,
end: 7,
value: 2,
raw: "2"
},
operator: "||="
}
}]
}, {
playground: true
});
test("obj.x ||= 2;", {
type: "Program",
start: 0,
end: 12,
body: [{
type: "ExpressionStatement",
start: 0,
end: 12,
expression: {
type: "AssignmentExpression",
start: 0,
end: 11,
left: {
type: "MemberExpression",
start: 0,
end: 5,
object: {
type: "Identifier",
start: 0,
end: 3,
name: "obj"
},
property: {
type: "Identifier",
start: 4,
end: 5,
name: "x"
},
computed: false
},
right: {
type: "Literal",
start: 10,
end: 11,
value: 2,
raw: "2"
},
operator: "||="
}
}]
}, {
playground: true
});
// Method binding
test("var fn = obj#method", {