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

Add and export utility classes for all types of nodes #87

Closed
emilos opened this issue Jul 31, 2020 · 0 comments
Closed

Add and export utility classes for all types of nodes #87

emilos opened this issue Jul 31, 2020 · 0 comments

Comments

@emilos
Copy link
Contributor

emilos commented Jul 31, 2020

Before:

    const statement = {
      type: 'IfStatement',
      test: {
        type: 'BinaryExpression',
        left: {
          type: 'MemberExpression',
          object: {
            type: 'Identifier',
            name: OBJECT_VARIABLE
          },
          property: { type: 'Identifier', name: 'language' }
        },
        right: { type: 'Literal', value: language },
        operator: '==='
      },
      consequent: {
        type: 'BlockStatement',
        body: [
          getTemplateAssignmentExpression(options.variables.template, { type: 'Literal', value: text.content })
        ]
      },
      alternate: null
    }

After:

    const statement = new IfStatement({
      test: new BinaryExpression({
        left: new MemberExpression({
          object: new Identifier({ name: OBJECT_VARIABLE }),
          property: new Identifier({ name: 'language' })
        }),
        right: new Literal({ value: language }),
        operator: '==='
      }),
      consequent: new BlockStatement({
        body: [
          getTemplateAssignmentExpression(options.variables.template, { type: 'Literal', value: text.content })
        ]
      })
    })

Those classes could throw if you forget to set a required property, e.g. BinaryExpression would throw if operator wouldn't be passed.

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

No branches or pull requests

1 participant