Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

glsl-inject-defines

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

glsl-inject-defines - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

3

package.json
{
"name": "glsl-inject-defines",
"version": "1.0.1",
"version": "1.0.2",
"description": "injects a #define statement into a shader source",

@@ -16,2 +16,3 @@ "main": "string.js",

"dependencies": {
"glsl-token-inject-block": "^1.0.0",
"glsl-token-string": "^1.0.1",

@@ -18,0 +19,0 @@ "glsl-tokenizer": "^2.0.2"

var tokenize = require('glsl-tokenizer')
var stringify = require('glsl-token-string')
var inject = require('glsl-token-inject-block')
var newline = {
type: 'whitespace',
data: '\n'
}
module.exports = function (source, defines) {
module.exports = function glslInjectDefine (source, defines) {
if (!defines) {

@@ -20,9 +16,4 @@ return source

var tokens = tokenize(source)
var idx = startIndex(tokens)
var last = tokens[idx - 1]
if (last) {
insert(tokens, idx++, newline)
}
keys.forEach(function (key) {
for (var i=keys.length-1; i>=0; i--) {
var key = keys[i]
var val = String(defines[key])

@@ -33,49 +24,9 @@ if (val) { // allow empty value

insert(tokens, idx++, {
inject(tokens, {
type: 'preprocessor',
data: '#define ' + key + val
})
insert(tokens, idx++, newline)
})
var src = stringify(tokens)
return src
}
function startIndex (tokens) {
// determine starting index for defines
var start = 0
for (var i = 0; i < tokens.length; i++) {
var token = tokens[i]
if (token.type === 'preprocessor') {
if (/^#(extension|version)/.test(token.data)) {
start = Math.max(start, i + 1)
}
}
}
return start
return stringify(tokens)
}
function insert (tokens, idx, token) {
// inserts a token at the start of a line
var last = tokens[idx - 1]
var line = last ? last.line : 0
var position = last ? (last.position + last.data.length) : 0
token = {
type: token.type,
data: token.data,
position: position,
line: line,
column: 0
}
tokens.splice(idx, 0, token)
var offset = token.data.length
while (idx < tokens.length) {
tokens[idx].position += offset
tokens[idx].line++
idx++
}
return token
}
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc