How to concatenate two arrays into one in Server Actions? (NodeJS)

Something like this?

Below you have a rough and quick approach. Unfortunately I don’t have much time to work on this but maybe you want to take a go at it if you really need it. There would be a lot of parsing and token filtering required but it’s doable as you can see above.

const { NodeVM } = require('vm2')
const Parser = require('../../../lib/core/parser');
exports.run = function (options) {
    let tokens = (Parser.lexer(options.code))
    let result = []
    tokens.forEach(function (e) {
        if (e.name === 'L_CURLY' || e.name === 'R_CURLY') {
        }
        else if (e.name === 'IDENT') { result.push(JSON.stringify(this.scope.get(e.value))) }
        else {
            result.push(e.value)
        }
    }.bind(this))
    let code = result.join('')
    const vm = new NodeVM();
    return vm.run('module.exports =' + code)
}
1 Like