Skip to content

Commit

Permalink
upgrade build script for edition nest
Browse files Browse the repository at this point in the history
  • Loading branch information
errorrik committed Aug 1, 2023
1 parent c17b224 commit b632bd9
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions tool/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ const MOZ_SourceMap = require('source-map');

let editions = {
'__': {
ignoreFeatures: ['devtool', 'error']
ignoreFeatures: ['devtool', 'error', 'modern']
},

min: {
ignoreFeatures: ['devtool', 'error'],
ignoreFeatures: ['devtool', 'error', 'modern'],
compress: 1
},

dev: {
ignoreFeatures: []
ignoreFeatures: ['modern']
},

'modern': {
Expand All @@ -34,16 +34,16 @@ let editions = {
},

spa: {
ignoreFeatures: ['devtool', 'hydrate', 'error']
ignoreFeatures: ['devtool', 'hydrate', 'error', 'modern']
},

'spa.min': {
ignoreFeatures: ['devtool', 'hydrate', 'error'],
ignoreFeatures: ['devtool', 'hydrate', 'error', 'modern'],
compress: 1
},

'spa.dev': {
ignoreFeatures: ['hydrate']
ignoreFeatures: ['hydrate', 'modern']
},

'spa.modern': {
Expand Down Expand Up @@ -142,28 +142,29 @@ function clearFeatureCode(source, ignoreFeatures) {
let endRule = /^\s*\/\/\s*#\[end\]\s*$/;

let featureRule = new RegExp('(' + ignoreFeatures.join('|') + ')');
let states = [];
let state = 0;
return source.split('\n')
.map(line => {
switch (state) {
case 1:
case 2:
if (endRule.test(line)) {
state = 0;
}
else if (state === 2) {
return '// ' + line;
}
break;

case 0:
let match;
if ((match = beginRule.exec(line))) {
state = featureRule.test(match[1]) ? 2 : 1;
}
break;
let match;
if ((match = beginRule.exec(line))) {
if (featureRule.test(match[1])) {
states.push(match[1]);
state++;
}
else {
states.push(0);
}
}

else if (endRule.test(line)) {
if (states.pop()) {
state--;
}
}
else if (state) {
return '// ' + line;
}

return line;
})
.join('\n');
Expand Down

0 comments on commit b632bd9

Please sign in to comment.