Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
babel-plugin-transform-es2015-typeof-symbol
Advanced tools
This transformer wraps all typeof expressions with a method that replicates native behaviour. (ie. returning “symbol” for symbols)
The babel-plugin-transform-es2015-typeof-symbol npm package is a plugin for Babel that ensures the behavior of the `typeof` operator is spec-compliant when used with symbols, a new primitive type introduced in ES2015 (ES6). It is part of the Babel's ES2015 preset and is used to transform code so that it can run in environments that do not natively support the new symbol type.
Transform typeof usage with symbols
This code sample demonstrates how the plugin transforms the `typeof` operator when used with a symbol. The plugin adds a helper function to correctly return 'symbol' when the operand is a symbol.
"use strict";
var _typeof = function (obj) {
return obj && obj.constructor === Symbol ? "symbol" : typeof obj;
};
var sym = Symbol('foo');
console.log(_typeof(sym) === 'symbol'); // true
This is the updated version of the babel-plugin-transform-es2015-typeof-symbol package, which is now scoped under the @babel namespace. It provides the same functionality but is maintained as part of the modern Babel 7 ecosystem.
This package is a Babel preset that includes babel-plugin-transform-es2015-typeof-symbol among other plugins to transform ES2015 code to be ES5 compliant. It is a more comprehensive solution that includes various transformations for ES2015 features.
ES6 introduces a new native type called symbols. This transformer wraps all
typeof
expressions with a method that replicates native behaviour. (ie. returning "symbol" for symbols)
In
typeof Symbol() === "symbol";
Out
var _typeof = function (obj) {
return obj && obj.constructor === Symbol ? "symbol" : typeof obj;
};
_typeof(Symbol()) === "symbol";
npm install --save-dev babel-plugin-transform-es2015-typeof-symbol
.babelrc
(Recommended).babelrc
{
"plugins": ["transform-es2015-typeof-symbol"]
}
babel --plugins transform-es2015-typeof-symbol script.js
require("babel-core").transform("code", {
plugins: ["transform-es2015-typeof-symbol"]
});
FAQs
This transformer wraps all typeof expressions with a method that replicates native behaviour. (ie. returning “symbol” for symbols)
We found that babel-plugin-transform-es2015-typeof-symbol demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.