Socket
Socket
Sign inDemoInstall

babel-plugin-remove-glsl-comments

Package Overview
Dependencies
4
Maintainers
5
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

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, '');
}

2

package.json
{
"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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc