-
Notifications
You must be signed in to change notification settings - Fork 78
About debugging components defined by the same name #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It took me a long time to find the reason. I think the problem occurred at the origin of generating SourceMap. Call stacks after it share this SourceMap data. Change file "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parse = void 0;
const source_map_1 = require("source-map");
+ const path = require('path');
const hash = require('hash-sum');
const cache = new (require('lru-cache'))(100);
const splitRE = /\r?\n/g;
const emptyRE = /^(?:\/\/)?\s*$/;
function parse(options) {
const { source, filename = '', compiler, compilerParseOptions = { pad: 'line' }, sourceRoot = '', needMap = true } = options;
const cacheKey = hash(filename + source + JSON.stringify(compilerParseOptions));
let output = cache.get(cacheKey);
if (output)
return output;
output = compiler.parseComponent(source, compilerParseOptions);
if (needMap) {
if (output.script && !output.script.src) {
output.script.map = generateSourceMap(filename, source, output.script.content, sourceRoot, compilerParseOptions.pad);
}
if (output.styles) {
output.styles.forEach(style => {
if (!style.src) {
style.map = generateSourceMap(filename, source, style.content, sourceRoot, compilerParseOptions.pad);
}
});
}
}
cache.set(cacheKey, output);
return output;
}
exports.parse = parse;
function generateSourceMap(filename, source, generated, sourceRoot, pad) {
+ filename = path.join(sourceRoot, filename).replace(/\\/g, '/')
const map = new source_map_1.SourceMapGenerator({
file: filename,
- sourceRoot: sourceRoot.replace(/\\/g, '/')
+ sourceRoot: ''
});
let offset = 0;
if (!pad) {
offset =
source
.split(generated)
.shift()
.split(splitRE).length - 1;
}
map.setSourceContent(filename, source);
generated.split(splitRE).forEach((line, index) => {
if (!emptyRE.test(line)) {
map.addMapping({
source: filename,
original: {
line: index + 1 + offset,
column: 0
},
generated: {
line: index + 1,
column: 0
}
});
}
});
return JSON.parse(map.toString());
} This is the final result: I think it's a problem of this package. In other files compiled with webpack, the sourceRoot is not used and paths in sources are always relative path not just a filename. The above code may not be the final solution, it just provides some suggestions. |
Version
3.2.0
Reproduction link
https://github.com/crixusshen/vuecli-debug-reproduction
Environment info
Steps to reproduce
I currently have two subcomponents with the same file name, although their implementations are different. Component A is located in 'src/components/A/HelloWorld.vue', Component B is located in 'src/components/B/HelloWorld.vue', although they are in A and B directories respectively, but their file names are called HelloWorld.vue.
Then use them separately in the main component:
And then the view rendering is really expected.But I had trouble debugging in chrome.During debugging, I tried to debug A component, but I could only call out the implementation script of B component.At this point its debug path is located at “webpack:///HelloWorld.vue?hash”.
At this point I infer that as long as the component has the same name as the file name, the one after will override the one before when debugging.At that moment, on this basis and I create the src/components/C/HelloWorld.vue,It really confirmed my hypothesis.
This can cause a lot of trouble during debugging or problems where the debug file is not found.
What is expected?
Able to debug different files with the same name in debugging
What is actually happening?
currently only debug the last component in the same file name
Related issue
vuejs/vue-cli#4535
The text was updated successfully, but these errors were encountered: