Skip to content

Commit

Permalink
fix: prevent from mutating original sfc, fixes #243
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Aug 12, 2021
1 parent 690df36 commit 0d41111
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -36,6 +36,7 @@
"fs-extra": "^9.1.0",
"is-binary-path": "^2.1.0",
"joycon": "^3.0.1",
"lodash.clonedeep": "^4.5.0",
"postcss": "^8.2.10",
"postcss-load-config": "^3.0.1",
"resolve": "^1.20.0",
Expand All @@ -49,6 +50,7 @@
"@types/fs-extra": "^8.0.0",
"@types/is-binary-path": "^2.1.0",
"@types/jest": "^26.0.14",
"@types/lodash.clonedeep": "^4.5.6",
"@types/node-sass": "^4.11.0",
"@types/stringify-attributes": "^2.0.0",
"@typescript-eslint/eslint-plugin": "^4.22.0",
Expand Down
12 changes: 8 additions & 4 deletions src/index.ts
Expand Up @@ -6,6 +6,7 @@ import isBinaryPath from 'is-binary-path'
import createDebug from 'debug'
import { parse } from '@vue/compiler-sfc'
import glob from 'fast-glob'
import cloneDeep from 'lodash.clonedeep'
import {
replaceContants,
cssExtensionsRe,
Expand All @@ -19,7 +20,7 @@ import { writeSFC } from './writeSFC'

const debug = createDebug('vue-compile:cli')

type OptionContants = Record<string, string | boolean | number>;
type OptionContants = Record<string, string | boolean | number>

interface InputOptions {
config?: boolean | string
Expand Down Expand Up @@ -127,9 +128,11 @@ class VueCompile extends EventEmitter {

ctx.transformTypeScript = !this.options.preserveTsBlock

const sfc = parse(source, {
filename: input,
})
const sfc = cloneDeep(
parse(source, {
filename: input,
}),
)

const script = await compileScript(sfc.descriptor.script, ctx)
const scriptSetup = await compileScript(sfc.descriptor.scriptSetup, ctx)
Expand Down Expand Up @@ -159,6 +162,7 @@ class VueCompile extends EventEmitter {
cwd: input,
ignore: ['**/node_modules/**'].concat(exclude),
})

await Promise.all(
files.map(async (file: string) => {
return this.normalizeFile(
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Expand Up @@ -1294,6 +1294,18 @@
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.3.tgz#bdfd69d61e464dcc81b25159c270d75a73c1a636"
integrity sha512-Il2DtDVRGDcqjDtE+rF8iqg1CArehSK84HZJCT7AMITlyXRBpuPhqGLDQMowraqqu1coEaimg4ZOqggt6L6L+A==

"@types/lodash.clonedeep@^4.5.6":
version "4.5.6"
resolved "https://registry.yarnpkg.com/@types/lodash.clonedeep/-/lodash.clonedeep-4.5.6.tgz#3b6c40a0affe0799a2ce823b440a6cf33571d32b"
integrity sha512-cE1jYr2dEg1wBImvXlNtp0xDoS79rfEdGozQVgliDZj1uERH4k+rmEMTudP9b4VQ8O6nRb5gPqft0QzEQGMQgA==
dependencies:
"@types/lodash" "*"

"@types/lodash@*":
version "4.14.172"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.172.tgz#aad774c28e7bfd7a67de25408e03ee5a8c3d028a"
integrity sha512-/BHF5HAx3em7/KkzVKm3LrsD6HZAXuXO1AJZQ3cRRBZj4oHZDviWPYu0aEplAqDFNHZPW6d3G7KN+ONcCCC7pw==

"@types/node-sass@^4.11.0":
version "4.11.0"
resolved "https://registry.yarnpkg.com/@types/node-sass/-/node-sass-4.11.0.tgz#b0372075546e83f39df52bd37359eab00165a04d"
Expand Down

0 comments on commit 0d41111

Please sign in to comment.