Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove forbidMultiLineImplicitObjectLiteral #613

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion source/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -2573,10 +2573,11 @@ function processPipelineExpressions(statements) {

function processProgram(root, config, m, ReservedWord) {
// invariants
assert.equal(m.forbidBracedApplication.length, 1, "forbidBracedApplication")
assert.equal(m.forbidClassImplicitCall.length, 1, "forbidClassImplicitCall")
assert.equal(m.forbidIndentedApplication.length, 1, "forbidIndentedApplication")
assert.equal(m.forbidNewlineBinaryOp.length, 1, "forbidNewlineBinaryOp")
assert.equal(m.forbidTrailingMemberProperty.length, 1, "forbidTrailingMemberProperty")
assert.equal(m.forbidMultiLineImplicitObjectLiteral.length, 1, "forbidMultiLineImplicitObjectLiteral")
assert.equal(m.JSXTagStack.length, 0, "JSXTagStack should be empty")

addParentPointers(root)
Expand Down
54 changes: 7 additions & 47 deletions source/parser.hera
Original file line number Diff line number Diff line change
Expand Up @@ -2235,7 +2235,7 @@ NestedImplicitPropertyDefinitions
return defs.flat()

NestedImplicitPropertyDefinition
Nested:ws ImplicitNamedProperty:prop ObjectPropertyDelimiter:delimiter ->
Nested:ws NamedProperty:prop ObjectPropertyDelimiter:delimiter ->
return {
...prop,
children: [...ws, ...prop.children, delimiter],
Expand Down Expand Up @@ -2269,7 +2269,7 @@ NestedPropertyDefinition
})

InlineObjectLiteral
InsertInlineOpenBrace:open SnugNamedProperty:first ( ImplicitInlineObjectPropertyDelimiter ImplicitNamedProperty )*:rest ( _? Comma &Dedented )?:trailing InsertCloseBrace:close ->
InsertInlineOpenBrace:open SnugNamedProperty:first ( ImplicitInlineObjectPropertyDelimiter NamedProperty )*:rest ( _? Comma &Dedented )?:trailing InsertCloseBrace:close ->
return {
type: "ObjectExpression",
children: [open, first, ...rest, trailing, close],
Expand All @@ -2279,7 +2279,7 @@ InlineObjectLiteral
# Instead we see if the next line matches a NamedProperty and if so we insert a comma
ImplicitInlineObjectPropertyDelimiter
_? Comma ( NotDedented / _? )
&( Samedent ImplicitNamedProperty ) InsertComma ( Samedent / _? ) -> [$2, $3]
&( Samedent NamedProperty ) InsertComma ( Samedent / _? ) -> [$2, $3]

ObjectPropertyDelimiter
_? Comma
Expand Down Expand Up @@ -2433,23 +2433,10 @@ NamedProperty
value: exp,
}

# NOTE: Variation on NamedProperty that forbids newlines after colon
# when forbidMultiLineImplicitObjectLiteral is set
ImplicitNamedProperty
PropertyName:name _? Colon ( MultiLineImplicitObjectLiteralAllowed / !EOS ) ExtendedExpression:exp ->
return {
type: "Property",
children: $0,
name: name,
names: exp.names || [],
value: exp,
}

# Named property but doesn't allow any space between name and colon
# used to distinguish between braceless inline objects and ternary expression conditions
# Only used by implicit object literals, so forbid newlines after colon
SnugNamedProperty
PropertyName Colon ( MultiLineImplicitObjectLiteralAllowed / !EOS ) ExtendedExpression:exp ->
PropertyName Colon ExtendedExpression:exp ->
return {
type: "Property",
children: $0,
Expand Down Expand Up @@ -3695,8 +3682,7 @@ ConditionFragment
}

CaseExpressionList
ForbidMultiLineImplicitObjectLiteral ( _? CaseExpression InsertColon )?:first ( __ Comma CaseExpression InsertColon )*:rest RestoreMultiLineImplicitObjectLiteral ->
if (!first) return $skip
( _? CaseExpression InsertColon ):first ( __ Comma CaseExpression InsertColon )*:rest ->
// Convert comma separated expression list to `case <exp>:`
const result = rest.map(([ws, _comma, exp, col]) => {
exp = insertTrimmingSpace(exp, "")
Expand Down Expand Up @@ -3932,25 +3918,6 @@ TrailingMemberPropertyAllowed
}
if (module.trailingMemberPropertyForbidden) return $skip

ForbidMultiLineImplicitObjectLiteral
"" ->
module.forbidMultiLineImplicitObjectLiteral.push(true)

AllowMultiLineImplicitObjectLiteral
"" ->
module.forbidMultiLineImplicitObjectLiteral.push(false)

RestoreMultiLineImplicitObjectLiteral
"" ->
module.forbidMultiLineImplicitObjectLiteral.pop()

MultiLineImplicitObjectLiteralAllowed
"" ->
if (module.config.verbose) {
console.log("forbidMultiLineImplicitObjectLiteral:", module.forbidMultiLineImplicitObjectLiteral)
}
if (module.multiLineImplicitObjectLiteralForbidden) return $skip

AllowNewlineBinaryOp
"" ->
module.forbidNewlineBinaryOp.push(false)
Expand All @@ -3971,10 +3938,10 @@ NewlineBinaryOpAllowed
if (module.newlineBinaryOpForbidden) return $skip

AllowAll
AllowTrailingMemberProperty AllowBracedApplication AllowIndentedApplication AllowMultiLineImplicitObjectLiteral AllowClassImplicitCall AllowNewlineBinaryOp
AllowTrailingMemberProperty AllowBracedApplication AllowIndentedApplication AllowClassImplicitCall AllowNewlineBinaryOp

RestoreAll
RestoreTrailingMemberProperty RestoreBracedApplication RestoreIndentedApplication RestoreMultiLineImplicitObjectLiteral RestoreClassImplicitCall RestoreNewlineBinaryOp
RestoreTrailingMemberProperty RestoreBracedApplication RestoreIndentedApplication RestoreClassImplicitCall RestoreNewlineBinaryOp

# https://262.ecma-international.org/#prod-ExpressionStatement
ExpressionStatement
Expand Down Expand Up @@ -6436,7 +6403,6 @@ Reset
module.forbidIndentedApplication = [false]
module.forbidBracedApplication = [false]
module.forbidTrailingMemberProperty = [false]
module.forbidMultiLineImplicitObjectLiteral = [false]
module.forbidNewlineBinaryOp = [false]
module.JSXTagStack = []

Expand Down Expand Up @@ -6475,12 +6441,6 @@ Reset
return s[s.length-1]
},
},
multiLineImplicitObjectLiteralForbidden: {
get() {
const {forbidMultiLineImplicitObjectLiteral: s} = module
return s[s.length-1]
},
},
newlineBinaryOpForbidden: {
get() {
const {forbidNewlineBinaryOp: s} = module
Expand Down