From 5ef0f14e0405f986f216b33e2a8dd8505f64b9a7 Mon Sep 17 00:00:00 2001 From: Avaer Kazmer Date: Mon, 22 Jul 2019 12:05:03 -0400 Subject: [PATCH] Add undefPredeclarations pass --- index.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/index.js b/index.js index e22d811..b6666b0 100644 --- a/index.js +++ b/index.js @@ -68,6 +68,8 @@ function transpile(isVertex, source, newVersion = defaultNewVersion) { } } } + + undefPredeclarations(tokens); return stringify(tokens) } @@ -123,6 +125,22 @@ function addGlsl2Extensions(tokens, i) { }])) } +function undefPredeclarations(tokens) { + for (;;) { + const startIndex = tokens.findIndex(t => t.type === 'preprocessor' && /^#ifdef\s+(?:GL_ARB_gpu_shader5|GL_NV_gpu_shader5)/.test(t.data)); + if (startIndex !== -1) { + const endIndex = findNextEndif(tokens, startIndex + 1); + if (endIndex !== -1) { + tokens.splice(startIndex, endIndex - startIndex + 1); + } else { + break; + } + } else { + break; + } + } +} + function versionify(tokens, newVersion) { for (var i = 0; i < tokens.length; i++) { var token = tokens[i]