Expression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const template = require('babel-template') | |
| const {parse} = require('babylon') | |
| const {transform} = require('@babel/core') | |
| const prettier = require('prettier') | |
| const assert = require('assert') | |
| const src = | |
| `function hoge(a: number): number { | |
| return a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const template = require('babel-template') | |
| const {parse} = require('babylon') | |
| const {transform} = require('@babel/core') | |
| const prettier = require('prettier') | |
| const src = | |
| `function hoge() { | |
| } | |
| ` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //@flow | |
| import peg from 'pegjs' | |
| import type { Code } from 'types' | |
| export default function pegjsHandler(code: Code): Code { | |
| if (code === '') { | |
| return '' | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require('path') | |
| const peg = require('pegjs') | |
| const pegHandler = (code, {eventPath, plugin, filename}) => { | |
| return peg.generate(code, {output: 'source', format: 'commonjs'}) | |
| } | |
| const jsonHandler = (code, {eventPath, plugin, filename}) => { | |
| const objectName = path.basename(filename, '.json').replace(/-[a-z]/g, s => s.substr(1).toUpperCase()) | |
| return `const ${objectName} = ${code}\nmodule.exports = ${objectName}` |
| where | Node | property | alias |
|---|---|---|---|
| core.js | ArrayExpression | elements (null, Expression, SpreadElement) | Expression |
| core.js | AssignmentExpression | operator (string), left (LVal), right (Expression) | Expression |
| core.js | BinaryExpression | operator (BINARY_OPERATORS), left (Expression), right (Expression) | Binary, Expression |
| core.js | Directive | value (DirectiveLiteral) | |
| core.js | DirectiveLiteral | value (string) | |
| core.js | BlockStatement | body (Statement), directives (Directive) | Scopable, BlockParent, Block, Statement |
| core.js | BreakStatement | label (Identifier) | Statement, Terminatorless, CompletionStatement |
| core.js | CallExpression | callee (Expression), arguments (Expression, SpreadElement, JSXNamespacedName), typeParameters (TypeParameterInstantiation), optional (true, false) | Expression |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const plugin = babel => { | |
| const {types: t} = babel | |
| return { | |
| inherits: inheritsOpts, | |
| name: 's2s-jsdoc-creator', | |
| visitor: { | |
| Function(nodePath, state) { | |
| const comment = `* | |
| * @hoge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const {transform} = require('babel-core') | |
| const src = 'function hoge() {}' | |
| const plugin = () => { | |
| const visitor = { | |
| Function: (nodePath) => { | |
| nodePath.addComment('leading', 'hoge') | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Fraction { | |
| constructor(num, denom) { | |
| this.num = num | |
| this.denom = denom | |
| this._reduce() | |
| } | |
| _reduce() { | |
| if (this.num === 0) { | |
| this.denom = 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const generateObject = (scope, ...nodes) => { | |
| return t.objectExpression( | |
| nodes.map(node => { | |
| return t.objectProperty(scope.generateUidIdentifier(), node) | |
| }) | |
| ) | |
| } |