babel-plugin-remove-glsl-comments
Advanced tools
Comparing version 0.1.0 to 1.0.0
25
index.js
@@ -1,7 +0,8 @@ | ||
const minimatch = require("minimatch") | ||
const minimatch = require("minimatch"); | ||
const path = require('path'); | ||
const INLINE_COMMENT_REGEX = /\s*\/\/.*/g; | ||
// inline comment is only safe to remove if it's followed by a return (i.e. end of comment) | ||
const INLINE_COMMENT_REGEX = /\s*\/\/.*[\n\r]/g; | ||
const BLOCK_COMMENT_REGEX = /\s*\/\*(\*(?!\/)|[^*])*\*\//g; | ||
const DEFAULT_PATTERNS = ['*.js']; | ||
const DEFAULT_PATTERNS = ['**/*.js']; | ||
@@ -11,5 +12,15 @@ module.exports = function _(opts) { | ||
visitor: { | ||
TemplateLiteral(path, state) { | ||
if(filterFile(state)) { | ||
path.node.quasis.forEach(node => { | ||
node.value = { | ||
raw: handleString(node.value.raw), | ||
cooked: handleString(node.value.cooked) | ||
}; | ||
}); | ||
} | ||
}, | ||
StringLiteral(path, state) { | ||
if(filterFile(state)) { | ||
path.node.value = path.node.value.replace(INLINE_COMMENT_REGEX, '').replace(BLOCK_COMMENT_REGEX, ''); | ||
path.node.value = handleString(path.node.value); | ||
} | ||
@@ -22,3 +33,3 @@ } | ||
function filterFile(state) { | ||
const filename = state.file.opts.filename; | ||
const {filename} = state; | ||
const patterns = state.opts.patterns || DEFAULT_PATTERNS; | ||
@@ -33,1 +44,5 @@ | ||
} | ||
function handleString(str) { | ||
return str.replace(INLINE_COMMENT_REGEX, '\n').replace(BLOCK_COMMENT_REGEX, ''); | ||
} |
{ | ||
"name": "babel-plugin-remove-glsl-comments", | ||
"version": "0.1.0", | ||
"version": "1.0.0", | ||
"description": "Babel plugin for removing glsl comments", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -36,2 +36,13 @@ # babel-plugin-remove-glsl-comments | ||
Note: for safety, this plugin does not remove dynamically generated comments, e.g. | ||
```js | ||
const vs = `/* MODULE ${name} STARTS */`; | ||
``` | ||
```js | ||
const vs = `// END OF ${name}`; | ||
``` | ||
## Installation | ||
@@ -38,0 +49,0 @@ |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
3266
40
1
94
1