HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/shop.komma.nl/node_modules/@vue/cli/lib/util/codemods/injectOptions.js
module.exports = function injectOptions (fileInfo, api, { injections }) {
  const j = api.jscodeshift
  const root = j(fileInfo.source)

  const toPropertyAST = i => {
    return j(`({${i}})`).nodes()[0].program.body[0].expression.properties[0]
  }

  const properties = root
    .find(j.NewExpression, {
      callee: { name: 'Vue' },
      arguments: [{ type: 'ObjectExpression' }]
    })
    .map(path => path.get('arguments', 0))
    .get()
    .node
    .properties

  const toPropertyHash = p => `${p.key.name}: ${j(p.value).toSource()}`
  const propertySet = new Set(properties.map(toPropertyHash))
  const nonDuplicates = p => !propertySet.has(toPropertyHash(p))

  // inject at index length - 1 as it's usually the render fn
  properties.splice(-1, 0, ...injections.map(toPropertyAST).filter(nonDuplicates))

  return root.toSource()
}