- Notifications
You must be signed in to change notification settings - Fork335
feat: add jsx support#391
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2434,8 +2434,90 @@ | ||
| ModuleSpecifier:function(expr,precedence,flags){ | ||
| returnthis.Literal(expr,precedence,flags); | ||
| }, | ||
| JSXIdentifier:function(expr,precedence,flags){ | ||
| returnexpr.name; | ||
| }, | ||
| JSXMemberExpression:function(expr,precedence,flags){ | ||
| varresult=[]; | ||
| result.push(this.generateExpression(expr.object,precedence,flags)); | ||
| result.push('.'); | ||
| result.push(this.generateExpression(expr.property,precedence,flags)); | ||
| returnresult; | ||
| }, | ||
| JSXNamespacedName:function(expr,precedence,flags){ | ||
| varresult=[]; | ||
| result.push(this.generateExpression(expr.namespace,precedence,flags)); | ||
| result.push(':'); | ||
| result.push(this.generateExpression(expr.name,precedence,flags)); | ||
| returnresult; | ||
| }, | ||
| JSXEmptyExpression:function(expr,precedence,flags){ | ||
| return''; | ||
| }, | ||
| JSXExpressionContainer:function(expr,precedence,flags){ | ||
| return['{',this.generateExpression(expr.expression,precedence,flags),'}']; | ||
| }, | ||
| JSXOpeningElement:function(expr,precedence,flags){ | ||
| varresult,i,iz; | ||
| result=['<']; | ||
| result.push(this.generateExpression(expr.name,precedence,flags)); | ||
| if(expr.attributes){ | ||
| for(i=0,iz=expr.attributes.length;i<iz;++i){ | ||
| result.push(' '); | ||
| result.push(this.generateExpression(expr.attributes[i],precedence,flags)); | ||
| } | ||
| } | ||
| result.push(expr.selfClosing ?[' />'] :'>'); | ||
erquhart marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| returnresult; | ||
| }, | ||
| JSXClosingElement:function(expr,precedence,flags){ | ||
| return['</',this.generateExpression(expr.name,precedence,flags),'>']; | ||
| }, | ||
| JSXAttribute:function(expr,precedence,flags){ | ||
| varresult=[]; | ||
| result.push(this.generateExpression(expr.name,precedence,flags)); | ||
| result.push('='); | ||
| if(expr.value.type==='Literal'){ | ||
| result.push(this.generateExpression(expr.value,precedence,flags)); | ||
| returnresult; | ||
| } | ||
| if(expr.value.type==='JSXExpressionContainer'){ | ||
| result.push(this.generateExpression(expr.value.expression,precedence,flags)); | ||
| returnresult; | ||
| } | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. You also need to handle >require('escodegen').generate(require('esprima').parse('(<Foo bar=<Quux/>/>)',{jsx:true}));'<Foo undefined />;' And Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Totally forgot about boolean attributes, good catch 👍 | ||
| }, | ||
| JSXSpreadAttribute:function(expr,precedence,flags){ | ||
| return['{...',this.generateExpression(expr.argument,precedence,flags),'}']; | ||
| }, | ||
| JSXText:function(expr,precedence,flags){ | ||
| returnexpr.value; | ||
| }, | ||
| JSXElement:function(expr,precedence,flags){ | ||
| varresult,i,iz; | ||
| result=[]; | ||
| result.push(this.generateExpression(expr.openingElement,precedence,flags)); | ||
| if(expr.children){ | ||
| for(i=0,iz=expr.children.length;i<iz;++i){ | ||
| result.push(this.generateExpression(expr.children[i],precedence,flags)); | ||
| } | ||
| } | ||
| if(expr.closingElement){ | ||
| result.push(this.generateExpression(expr.closingElement,precedence,flags)); | ||
| } | ||
| returnresult; | ||
| } | ||
| }; | ||
| merge(CodeGenerator.prototype,CodeGenerator.Expression); | ||
Uh oh!
There was an error while loading.Please reload this page.