Skip to content

Commit 900b941

Browse files
committed
local -> scoped
1 parent 8bbc858 commit 900b941

File tree

8 files changed

+19
-19
lines changed

8 files changed

+19
-19
lines changed

lib/loader.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ module.exports = function (content) {
2727
loaders.css = loaders.css || 'style!css'
2828
loaders.js = loaders.js || ''
2929

30-
function getRequire (type, part, index, local) {
30+
function getRequire (type, part, index, scoped) {
3131
return 'require(' +
3232
loaderUtils.stringifyRequest(self,
3333
// disable system loaders (except post loaders)
3434
'-!' +
3535
// get loader string for pre-processors
36-
getLoaderString(type, part, local) +
36+
getLoaderString(type, part, scoped) +
3737
// select the corresponding part from the vue file
3838
getSelectorString(type, index || 0) +
3939
// the url to the actual vuefile
@@ -46,15 +46,15 @@ module.exports = function (content) {
4646
return 'require(' +
4747
loaderUtils.stringifyRequest(self,
4848
'-!' +
49-
getLoaderString('style', impt, impt.local) +
49+
getLoaderString('style', impt, impt.scoped) +
5050
impt.src
5151
) +
5252
')\n'
5353
}
5454

55-
function getLoaderString (type, part, local) {
55+
function getLoaderString (type, part, scoped) {
5656
var lang = part.lang || defaultLang[type]
57-
var rewriter = local ? rewriters[type] || '' : ''
57+
var rewriter = scoped ? rewriters[type] || '' : ''
5858
var loader = loaders[lang]
5959
if (loader !== undefined) {
6060
// lang with default or pre-configured loader
@@ -91,14 +91,14 @@ module.exports = function (content) {
9191

9292
// add requires for src imports
9393
parts.styleImports.forEach(function (impt) {
94-
if (impt.local) hasLocalStyles = true
94+
if (impt.scoped) hasLocalStyles = true
9595
output += getRequireForImport(impt)
9696
})
9797

9898
// add requires for styles
9999
parts.style.forEach(function (style, i) {
100-
if (style.local) hasLocalStyles = true
101-
output += getRequire('style', style, i, style.local)
100+
if (style.scoped) hasLocalStyles = true
101+
output += getRequire('style', style, i, style.scoped)
102102
})
103103

104104
// only one script tag allowed

lib/parser.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = function (content) {
1717
var type = node.tagName
1818
var lang = getAttribute(node, 'lang')
1919
var src = getAttribute(node, 'src')
20-
var local = getAttribute(node, 'local') != null
20+
var scoped = getAttribute(node, 'scoped') != null
2121

2222
if (src) {
2323
if (type !== 'style') {
@@ -28,7 +28,7 @@ module.exports = function (content) {
2828
output.styleImports.push({
2929
src: src,
3030
lang: lang,
31-
local: local
31+
scoped: scoped
3232
})
3333
return
3434
}
@@ -63,7 +63,7 @@ module.exports = function (content) {
6363
var end = node.childNodes[node.childNodes.length - 1].__location.end
6464
output[type].push({
6565
lang: lang,
66-
local: local,
66+
scoped: scoped,
6767
content: content.substring(start, end).trim()
6868
})
6969
})
File renamed without changes.

test/fixtures/import.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<style src="./import.css"></style>
2-
<style src="./import.local.css" local></style>
2+
<style src="./import-scoped.css" scoped></style>

test/fixtures/local-css.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/fixtures/scoped-css.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
window.testModule = require('./scoped-css.vue')

test/fixtures/local-css.vue renamed to test/fixtures/scoped-css.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<style local>
1+
<style scoped>
22
body {
33
color: yellow;
44
}

test/test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ describe('vue-loader', function () {
8989
})
9090
})
9191

92-
it('local style', function (done) {
92+
it('scoped style', function (done) {
9393
test({
94-
entry: './test/fixtures/local-css.js'
94+
entry: './test/fixtures/scoped-css.js'
9595
}, function (window) {
9696
var module = window.testModule
97-
var cls = '.v-' + hash(require.resolve('./fixtures/local-css.vue'))
97+
var cls = '.v-' + hash(require.resolve('./fixtures/scoped-css.vue'))
9898
expect(module.template).to.contain(
9999
'<div class="' + cls.slice(1) + '"><h1>hi</h1></div>\n' +
100100
'<p class="abc def ' + cls.slice(1) + '">hi</p>'
@@ -119,8 +119,8 @@ describe('vue-loader', function () {
119119
}, function (window) {
120120
var styles = window.document.querySelectorAll('style')
121121
expect(styles[0].textContent).to.contain('h1 { color: red; }')
122-
// import with local
123-
var cls = '.v-' + hash(require.resolve('./fixtures/import.local.css'))
122+
// import with scoped
123+
var cls = '.v-' + hash(require.resolve('./fixtures/import-scoped.css'))
124124
expect(styles[1].textContent).to.contain(cls + ' h1 {\n color: green;\n}')
125125
done()
126126
})

0 commit comments

Comments
 (0)