MCPcopy Create free account
hub / github.com/mozilla/rhino / plainProperty

Method plainProperty

rhino/src/main/java/org/mozilla/javascript/Parser.java:4282–4310  ·  view source on GitHub ↗
(AstNode property, int ptt)

Source from the content-addressed store, hash-verified

4280 }
4281
4282 private ObjectProperty plainProperty(AstNode property, int ptt) throws IOException {
4283 // Support, e.g., |var {x, y} = o| as destructuring shorthand
4284 // for |var {x: x, y: y} = o|, as implemented in spidermonkey JS 1.8.
4285 int tt = peekToken();
4286 if ((tt == Token.COMMA || tt == Token.RC)
4287 && ptt == Token.NAME
4288 && compilerEnv.getLanguageVersion() >= Context.VERSION_1_8) {
4289 if (!inDestructuringAssignment
4290 && compilerEnv.getLanguageVersion() < Context.VERSION_ES6) {
4291 reportError("msg.bad.object.init");
4292 }
4293 AstNode nn = new Name(property.getPosition(), property.getString());
4294 ObjectProperty pn = new ObjectProperty();
4295 pn.setKeyAndValue(property, nn);
4296 return pn;
4297 } else if (tt == Token.ASSIGN) {
4298 /* we're in destructuring with defaults in a object literal; treat defaults as values */
4299 ObjectProperty pn = new ObjectProperty();
4300 consumeToken(); // consume the `=`
4301 Assignment defaultValue = new Assignment(property, assignExpr());
4302 defaultValue.setType(Token.ASSIGN);
4303 pn.setKeyAndValue(property, defaultValue);
4304 return pn;
4305 }
4306 mustMatchToken(Token.COLON, "msg.no.colon.prop", true);
4307 ObjectProperty pn = new ObjectProperty();
4308 pn.setKeyAndValue(property, assignExpr());
4309 return pn;
4310 }
4311
4312 private ObjectProperty methodDefinition(
4313 int pos, AstNode propName, int entryKind, boolean isGenerator, boolean isShorthand)

Callers 1

objectLiteralMethod · 0.95

Calls 10

peekTokenMethod · 0.95
reportErrorMethod · 0.95
setKeyAndValueMethod · 0.95
consumeTokenMethod · 0.95
assignExprMethod · 0.95
mustMatchTokenMethod · 0.95
getPositionMethod · 0.65
getLanguageVersionMethod · 0.45
getStringMethod · 0.45
setTypeMethod · 0.45

Tested by

no test coverage detected