Skip to content

jirutka/babel-preset-njs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

babel-preset-njs

npm Version CI State

A Babel preset for transforming JavaScript code with modern language features into code compatible with njs (NGINX JavaScript). This preset includes support for all the ECMAScript features up to ES2021 — see Plugins for a complete list.

TIP: Take a look at njs-typescript-starter for a complete starter template for developing njs scripts for NGINX server in TypeScript (including integration tests).

Installation

# using npm:
npm install --save-dev babel-preset-njs
# or using yarn:
yarn add --dev babel-preset-njs

Compatibility Matrix

preset-njs njs Babel

0.1.0 – 0.2.1

≥ 0.5.0

7

0.7.0

≥ 0.7.0

7

Usage

{
  "presets": ["babel-preset-njs"]
}

Via CLI

babel --presets babel-preset-njs script.js

Via Node API

require('@babel/core').transform('code', {
  presets: [require('babel-preset-njs')],
})

Plugins

The following table lists all relevant Babel transform plugins for ECMAScript features up to ES2021.

The State column is one of:

  • ✓ included — The plugin is included in this preset, i.e. njs doesn’t support this feature (or part of it) yet.

  • ✗ not needed — The plugin is not needed, i.e. njs already supports this feature.

  • ⚠ incompatible — The plugin is not compatible with njs, i.e. requires features that njs doesn’t support yet.

Plugin ECMAScript State Notes

member-expression-literals

ES3

✗ not needed

property-literals

ES3

✗ not needed

reserved-words

ES3

✗ not needed

property-mutators

ES5

✗ not needed

arrow-functions

ES2015

✗ not needed

block-scoped-functions

ES2015

✗ not needed

block-scoping

ES2015

✗ not needed

since njs 0.6.0

classes

ES2015

✓ included

computed-properties

ES2015

✗ not needed

since njs 0.3.4

destructuring

ES2015

✓ included

duplicate-keys

ES2015

✗ not needed

for-of

ES2015

✗ not needed

function-name

ES2015

⚠ incompatible

njs bug #360

instanceof

ES2015

✗ not needed

literals

ES2015

✗ not needed

new-target

ES2015

✗ not needed

object-super

ES2015

✓ included

parameters

ES2015

✓ included

Only rest parameters are supported.

shorthand-properties

ES2015

✗ not needed

spread

ES2015

✓ included

sticky-regex

ES2015

✗ not needed

since njs 0.6.0

template-literals

ES2015

✗ not needed

typeof-symbol

ES2015

✗ not needed

unicode-escapes

ES2015

✗ not needed

Supported, but not in identifiers (e.g. variable name).

unicode-regex

ES2015

✓ included

exponentiation-operator

ES2016

✗ not needed

async-to-generator

ES2017

✗ not needed

since njs 0.7.0

async-generator-functions

ES2018

⚠ incompatible

njs doesn’t support generators yet

dotall-regex

ES2018

✓ included

named-capturing-groups-regex

ES2018

✗ not needed

object-rest-spread

ES2018

✓ included

unicode-property-regex

ES2018

✓ included

optional-catch-binding

ES2019

✓ included

json-strings

ES2019

✗ not needed

dynamic-import

ES2020

⚠ incompatible

njs has only limited support of ES modules.

export-namespace-from

ES2020

✓ included

nullish-coalescing-operator

ES2020

✗ not needed

optional-chaining

ES2020

✓ included

logical-assignment-operators

ES2021

✓ included

numeric-separator

ES2021

✗ not needed

Enabled Assumptions

The following assumptions are enabled for better performance and match with the behaviour of the TypeScript transpiler.

License

This project is licensed under MIT License.

About

A Babel preset for njs - NGINX JavaScript

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project