5.6.3 • Published 7 years ago

transform-dwayne-js-expressions v5.6.3

Weekly downloads
82
License
-
Repository
-
Last release
7 years ago

transform-dwayne-js-expressions

The plugin is needed for transforming Dwayne javascript expressions.

Installation

npm install --save transform-dwayne-js-expressions

Usage

const transformDwayneJs = require('transform-dwayne-js-expressions');

const transformed = transformDwayneJs('Math.sin(a) + b', {
  filename: 'test.js',
  sourceMap: true,
  unscopables: ['Math']
});

// {
//   code: `function (_) {
//     return Math.sin(_.a) + _.b;
//   }`,
//   map: { ... },
//   vars: ['a', 'b']
// }

API

transformDwayneJs(code: string, options?: {
  filename?: string = 'unknown',
  sourceMap?: boolean = true,
  unscopables?: string[] = ['require'],
  keepScope?: boolean = false,
  thisVarName?: string = '_this',
  useES6?: boolean = false
}): {
  code: string,
  map: SourceMap | null,
  vars: string[],
  generatedThisVar: boolean
}
  • options.filename (default: 'unknown'): filename for sourcemaps.
  • options.sourceMap (default: true): if it's needed to produce a sourcemap.
  • options.unscopables (default: ['require']): an array of the vars that aren't meant to be in the block scope.
  • options.keepScope (default: false): if it is needed to prefix the variables with the scope var.
  • options.thisVarName (default: '_this'): in the case when options.keepScope is set to true all occurrences of this are replaced with this value.
  • options.useES6 (default: false): if it is needed to use es6: generating an arrow function instead of usual function and not generating options.keepScope identifier. It's better to set this option to true and leave transforming ES6 into ES5 to babel or other similar tools.
  • options.startLine (default: 1): used for error messages.
  • options.startColumn (default: 0): used for error messages.
  • options.startPosition (default: 0): used for error messages.

Returns an object with the following properties:

  • code: generated code.
  • map: generated sourcemap.
  • vars: used scope vars.
  • generatedThisVar: whether options.thisVarName was generated or not.
5.6.3

7 years ago

5.6.2

7 years ago

5.6.1

7 years ago

5.6.0

7 years ago

5.5.0

7 years ago

5.4.2

7 years ago

5.4.1

7 years ago

5.4.0

7 years ago

5.3.0

7 years ago

5.2.2

7 years ago

5.2.1

7 years ago

5.2.0

7 years ago

5.1.0

7 years ago

5.0.2

7 years ago

5.0.1

7 years ago

5.0.0

7 years ago