Skip to content

Commit f62b8d2

Browse files
committed
Path passed up in the hierarchy is now the one of the current module instead of being always the one from the leaf component
1 parent e69fad2 commit f62b8d2

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const loader = function (source, map) {
2727
// To make HMR aware of the base file and reload it when it changes
2828
result.ancestorsPaths.forEach(ancestor => {
2929
this.addDependency(ancestor);
30-
})
30+
});
3131

3232
callback(null,
3333
result.source,
@@ -37,9 +37,9 @@ const loader = function (source, map) {
3737
});
3838
};
3939

40-
const getMergedCode = function (source, initialPath) {
40+
const getMergedCode = function (source, currPath) {
4141
return new Promise((resolve, reject) => {
42-
resolveComponent(source, initialPath).then(({source, ancestorsPaths}) => {
42+
resolveComponent(source, currPath).then(({source, ancestorsPaths}) => {
4343

4444
// Remove comment lines at beginning of script block that were generated by the SFC parser
4545
let finalDescriptor = toDescriptor(source);
@@ -65,9 +65,9 @@ const getMergedCode = function (source, initialPath) {
6565
reject(error)
6666
});
6767
})
68-
}
68+
};
6969

70-
function resolveComponent(currentSource, initialPath) {
70+
function resolveComponent(currentSource, currPath) {
7171
return new Promise((resolve, reject) => {
7272
try {
7373
let currentDesc = toDescriptor(currentSource);
@@ -76,14 +76,15 @@ function resolveComponent(currentSource, initialPath) {
7676
// else return code as is
7777
if (currentDesc.template && currentDesc.template.attrs[options.EXTENDS_ATTR]) {
7878
let baseRelPath = currentDesc.template.attrs[options.EXTENDS_ATTR];
79-
let baseAbsPath = path.join(initialPath, baseRelPath);
79+
let baseAbsPath = path.join(currPath, baseRelPath);
8080

8181
fs.readFile(baseAbsPath, 'utf8', (err, contents) => {
8282
// File read error, reject
8383
if (err) reject(err);
8484

8585
// Resolve the base component recursively to support inheritance in N levels
86-
resolveComponent(contents, initialPath).then(({source, ancestorsPaths}) => {
86+
let basePath = path.dirname(baseAbsPath);
87+
resolveComponent(contents, basePath).then(({source, ancestorsPaths}) => {
8788
try {
8889
// Add this ancestor to the ancestors return array
8990
ancestorsPaths.push(baseAbsPath);

0 commit comments

Comments
 (0)