Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
fix: update gen-id implementation (#43)
Browse files Browse the repository at this point in the history
* fix: update gen-id implementation

fixes #42

* fix: add data-v prefix to generated scope id
  • Loading branch information
znck authored Jan 13, 2018
1 parent f8a36c7 commit 72ff0bb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
10 changes: 2 additions & 8 deletions src/gen-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
// used in scoped CSS rewriting
const path = require('path')
const hash = require('hash-sum')
const cache = Object.create(null)
const sepRE = new RegExp(path.sep.replace('\\', '\\\\'), 'g')

module.exports = function genId (file, context, key) {
const contextPath = context.split(path.sep)
const rootId = contextPath[contextPath.length - 1]
file = rootId + '/' + path.relative(context, file).replace(sepRE, '/') + (key || '')

return cache[file] || (cache[file] = 'data-v-' + hash(file))
module.exports = function genId (filename, content, isProduction = true) {
return 'data-v' + (isProduction ? hash(path.basename(filename) + '\n' + content) : hash(filename))
}
2 changes: 1 addition & 1 deletion test/setup/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function load (ext, handle) {
function compile (filename, source) {
source = source || readFileSync(filename).toString()
const descriptor = compiler.parse(source, filename, { needMap: true })
const scopeId = compiler.generateScopeId(filename, join(__dirname, 'fixtures'))
const scopeId = compiler.generateScopeId(filename, source)
const render = descriptor.template ? compiler.compileTemplate(
{ code: descriptor.template.content, descriptor: descriptor.template }, filename, { scopeId }
) : null
Expand Down

0 comments on commit 72ff0bb

Please sign in to comment.