babel-plugin-const-enum
Advanced tools
Comparing version 0.0.5 to 1.0.0
@@ -18,3 +18,2 @@ "use strict"; | ||
path.replaceWith(_core.types.variableDeclaration('const', [_core.types.variableDeclarator(_core.types.identifier(path.node.id.name), _core.types.objectExpression(TSEnumMembersToObjectProperties(path.get('members'))))])); | ||
path.skip(); | ||
} | ||
@@ -31,3 +30,2 @@ } | ||
return memberPaths.map(tsEnumMemberPath => { | ||
const tsEnumMember = tsEnumMemberPath.node; | ||
const keyNode = computeKeyNodeFromIdPath(tsEnumMemberPath.get('id')); | ||
@@ -101,7 +99,7 @@ const key = getKeyFromKeyNode(keyNode); | ||
} else { | ||
throw initializerPath.buildCodeFrameError('Enum initializer must be a string literal or numeric expression.'); | ||
throw initializerPath.buildCodeFrameError('const enum member initializers can only contain literal values and other computed enum values.'); | ||
} | ||
} else { | ||
if (currentValue === null) { | ||
throw tsEnumMemberPath.buildCodeFrameError('Enum member must have initializer..'); | ||
throw tsEnumMemberPath.buildCodeFrameError('Enum member must have initializer.'); | ||
} | ||
@@ -136,6 +134,9 @@ | ||
const isNumericUnaryExpression = node => _core.types.isUnaryExpression(node) && new Set(['+', '-', '~']).has(node.operator); | ||
const UNARY_OPERATORS = new Set(['+', '-', '~']); | ||
const BINARY_OPERATORS = new Set(['+', '-', '/', '%', '*', '**', '&', '|', '>>', '>>>', '<<', '^']); | ||
const isNumericBinaryExpression = node => _core.types.isBinaryExpression(node) && new Set(['+', '-', '/', '%', '*', '**', '&', '|', '>>', '>>>', '<<', '^']).has(node.operator); | ||
const isNumericUnaryExpression = node => _core.types.isUnaryExpression(node) && UNARY_OPERATORS.has(node.operator); | ||
const isNumericBinaryExpression = node => _core.types.isBinaryExpression(node) && BINARY_OPERATORS.has(node.operator); | ||
const validateConstEnumMemberAccess = (path, value) => { | ||
@@ -142,0 +143,0 @@ if (value === undefined) { |
{ | ||
"name": "babel-plugin-const-enum", | ||
"version": "0.0.5", | ||
"version": "1.0.0", | ||
"description": "Transform TypeScript `const` enums", | ||
@@ -37,5 +37,5 @@ "repository": "https://github.com/dosentmatter/babel-plugin-const-enum", | ||
"@babel/preset-env": "^7.5.0", | ||
"babel-jest": "^24.8.0", | ||
"jest": "^24.8.0", | ||
"prettier": "^1.18.2" | ||
"babel-jest": "^25.2.6", | ||
"jest": "^25.2.7", | ||
"prettier": "^2.0.4" | ||
}, | ||
@@ -42,0 +42,0 @@ "files": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
11838
1