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

Empty value for optional JSX property causing exception in transpiler #2268

Open
mor-n4 opened this issue Nov 18, 2021 · 1 comment
Open
Labels

Comments

@mor-n4
Copy link
Contributor

mor-n4 commented Nov 18, 2021

Exception:

Severe error occurred in transpiler=es message=element to process may not be null.
java.lang.IllegalArgumentException: element to process may not be null
	at org.eclipse.n4js.transpiler.print.PrettyPrinterEcmaScript.process(PrettyPrinterEcmaScript.java:1257)
	at org.eclipse.n4js.transpiler.print.PrettyPrinterEcmaScript.caseParenExpression(PrettyPrinterEcmaScript.java:691)
	at org.eclipse.n4js.transpiler.print.PrettyPrinterEcmaScript.caseParenExpression(PrettyPrinterEcmaScript.java:1)
	at org.eclipse.n4js.n4JS.util.N4JSSwitch.doSwitch(N4JSSwitch.java:745)
	at org.eclipse.n4js.transpiler.print.PrettyPrinterEcmaScript.doSwitch(PrettyPrinterEcmaScript.java:82)
	at org.eclipse.n4js.transpiler.print.PrettyPrinterEcmaScript.doSwitch(PrettyPrinterEcmaScript.java:1)
	at org.eclipse.emf.ecore.util.Switch.doSwitch(Switch.java:53)
	at org.eclipse.n4js.transpiler.print.PrettyPrinterEcmaScript.doSwitch(PrettyPrinterEcmaScript.java:75)
	at org.eclipse.n4js.transpiler.print.PrettyPrinterEcmaScript.doSwitch(PrettyPrinterEcmaScript.java:1)
	at org.eclipse.emf.ecore.util.Switch.doSwitch(Switch.java:69)

To reproduce:

import * as React from "react";

export public interface ~MyProps {
    public header?: React.ReactElement<?>;
}

export public function MyElement(props: MyProps): React.ReactElement<?> {
	return null;
}


let elem = <MyElement header={(
)}>

</MyElement>;

Note: if the line break after let elem = <MyElement header={( is removed, a syntax error is shown.

@mor-n4 mor-n4 added the bug label Nov 18, 2021
@mor-n4
Copy link
Contributor Author

mor-n4 commented Nov 18, 2021

This seems to be a bug in the parser: it seems to accept empty parenthesis expression if they contain a line break.

The above exception can be reproduced with the following code:

let x = (
);

When removing the line break, the parser correctly emits a syntax error:

let x = (); // error: no viable alternative at input ')'

(BTW: if this is true, it makes sense that the transpiler throws an exception.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant