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
Emit inline comments inside dynamic import #2797
Merged
lukastaegert
merged 3 commits into
rollup:master
from
manucorporat:fix-inline-comments-import
Apr 10, 2019
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
test/chunking-form/samples/aliasing-extensions/_expected/amd/main1.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
define(['require'], function (require) { 'use strict'; | ||
|
||
console.log('main1'); | ||
new Promise(function (resolve, reject) { require(['./generated-chunk.js'], resolve, reject) }); | ||
new Promise(function (resolve, reject) { require(['./generated-chunk2.js'], resolve, reject) }); | ||
new Promise(function (resolve, reject) { require([('./generated-chunk.js')], resolve, reject) }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great work! These added parentheses are basically the only thing that is not as nice as it could be. But there is a possible solution... |
||
new Promise(function (resolve, reject) { require([('./generated-chunk2.js')], resolve, reject) }); | ||
|
||
}); |
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/dynamic-import-chained/_expected/amd/generated-chunk2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
define(['require'], function (require) { 'use strict'; | ||
|
||
console.log('dep1'); | ||
new Promise(function (resolve, reject) { require(['./generated-chunk.js'], resolve, reject) }); | ||
new Promise(function (resolve, reject) { require([('./generated-chunk.js')], resolve, reject) }); | ||
|
||
}); |
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/dynamic-import-chained/_expected/amd/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
define(['require'], function (require) { 'use strict'; | ||
|
||
console.log('main'); | ||
new Promise(function (resolve, reject) { require(['./generated-chunk2.js'], resolve, reject) }); | ||
new Promise(function (resolve, reject) { require([('./generated-chunk2.js')], resolve, reject) }); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
test/chunking-form/samples/dynamic-import-comments/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module.exports = { | ||
description: 'should not remove inline comments inside dynamic import', | ||
options: { | ||
input: 'main.js', | ||
onwarn() {}, | ||
plugins: { | ||
resolveDynamicImport() { | ||
return false; | ||
} | ||
}, | ||
output: { | ||
dynamicImportFunction: 'foobar' | ||
} | ||
} | ||
}; |
5 changes: 5 additions & 0 deletions
5
test/chunking-form/samples/dynamic-import-comments/_expected/amd/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
define(['require'], function (require) { 'use strict'; | ||
|
||
new Promise(function (resolve, reject) { require([ ( /* webpackChunkName: "chunk-name" */ './foo.js'/*suffix*/)], resolve, reject) }); | ||
|
||
}); |
3 changes: 3 additions & 0 deletions
3
test/chunking-form/samples/dynamic-import-comments/_expected/cjs/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
Promise.resolve(require ( /* webpackChunkName: "chunk-name" */ './foo.js'/*suffix*/)); |
1 change: 1 addition & 0 deletions
1
test/chunking-form/samples/dynamic-import-comments/_expected/es/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
foobar ( /* webpackChunkName: "chunk-name" */ './foo.js'/*suffix*/); |
10 changes: 10 additions & 0 deletions
10
test/chunking-form/samples/dynamic-import-comments/_expected/system/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
System.register([], function (exports, module) { | ||
'use strict'; | ||
return { | ||
execute: function () { | ||
|
||
module.import ( /* webpackChunkName: "chunk-name" */ './foo.js'/*suffix*/); | ||
|
||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import ( /* webpackChunkName: "chunk-name" */ './foo.js'/*suffix*/); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/dynamic-import-external/_expected/amd/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
define(['require'], function (require) { 'use strict'; | ||
|
||
new Promise(function (resolve, reject) { require(['./foo.js'], resolve, reject) }); | ||
new Promise(function (resolve, reject) { require([('./foo.js')], resolve, reject) }); | ||
|
||
}); |
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/dynamic-import-facade/_expected/amd/main1.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
define(['require'], function (require) { 'use strict'; | ||
|
||
new Promise(function (resolve, reject) { require(['./generated-chunk2.js'], resolve, reject) }).then(({dynamic}) => console.log('main1', dynamic)); | ||
new Promise(function (resolve, reject) { require([('./generated-chunk2.js')], resolve, reject) }).then(({dynamic}) => console.log('main1', dynamic)); | ||
|
||
}); |
4 changes: 2 additions & 2 deletions
4
test/chunking-form/samples/dynamic-import-inline-colouring/_expected/amd/main1.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/dynamic-import-inline-colouring/_expected/amd/main2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/dynamic-import-name/_expected/amd/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
define(['require'], function (require) { 'use strict'; | ||
|
||
new Promise(function (resolve, reject) { require(['./foo.js'], resolve, reject) }).then(result => console.log(result)); | ||
new Promise(function (resolve, reject) { require([('./foo.js')], resolve, reject) }).then(result => console.log(result)); | ||
|
||
}); |
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/dynamic-import-only-reexports/_expected/amd/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
define(['require'], function (require) { 'use strict'; | ||
|
||
new Promise(function (resolve, reject) { require(['./generated-chunk.js'], resolve, reject) }).then(({ value }) => console.log(value)); | ||
new Promise(function (resolve, reject) { require([('./generated-chunk.js')], resolve, reject) }).then(({ value }) => console.log(value)); | ||
|
||
}); |
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/amd/main2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
define(['require'], function (require) { 'use strict'; | ||
|
||
new Promise(function (resolve, reject) { require(['./generated-chunk2.js'], resolve, reject) }).then(({ bar }) => console.log(bar())); | ||
new Promise(function (resolve, reject) { require([('./generated-chunk2.js')], resolve, reject) }).then(({ bar }) => console.log(bar())); | ||
|
||
}); |
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/amd/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
define(['require'], function (require) { 'use strict'; | ||
|
||
new Promise(function (resolve, reject) { require(['./generated-dynamic2.js'], resolve, reject) }).then(result => console.log(result)); | ||
new Promise(function (resolve, reject) { require(['./generated-dynamic.js'], resolve, reject) }).then(result => console.log(result)); | ||
new Promise(function (resolve, reject) { require([('./generated-dynamic2.js')], resolve, reject) }).then(result => console.log(result)); | ||
new Promise(function (resolve, reject) { require([('./generated-dynamic.js')], resolve, reject) }).then(result => console.log(result)); | ||
|
||
}); |
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/manual-chunks-dynamic/_expected/amd/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
define(['require'], function (require) { 'use strict'; | ||
|
||
new Promise(function (resolve, reject) { require(['./generated-dynamic.js'], resolve, reject) }).then(({DYNAMIC_USED_BY_A}) => console.log(DYNAMIC_USED_BY_A)); | ||
new Promise(function (resolve, reject) { require([('./generated-dynamic.js')], resolve, reject) }).then(({DYNAMIC_USED_BY_A}) => console.log(DYNAMIC_USED_BY_A)); | ||
|
||
}); |
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
define(['require'], function (require) { 'use strict'; | ||
|
||
new Promise(function (resolve, reject) { require(['./generated-chunk2.js'], resolve, reject) }); | ||
new Promise(function (resolve, reject) { require([('./generated-chunk2.js')], resolve, reject) }); | ||
console.log('dynamic1'); | ||
|
||
}); |
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
define(['require'], function (require) { 'use strict'; | ||
|
||
new Promise(function (resolve, reject) { require(['./generated-chunk3.js'], resolve, reject) }); | ||
new Promise(function (resolve, reject) { require([('./generated-chunk3.js')], resolve, reject) }); | ||
console.log('dynamic2'); | ||
|
||
}); |
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk3.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
define(['require'], function (require) { 'use strict'; | ||
|
||
new Promise(function (resolve, reject) { require(['./generated-chunk4.js'], resolve, reject) }); | ||
new Promise(function (resolve, reject) { require([('./generated-chunk4.js')], resolve, reject) }); | ||
console.log('dynamic3'); | ||
|
||
}); |
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk4.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
define(['require'], function (require) { 'use strict'; | ||
|
||
new Promise(function (resolve, reject) { require(['./generated-chunk5.js'], resolve, reject) }); | ||
new Promise(function (resolve, reject) { require([('./generated-chunk5.js')], resolve, reject) }); | ||
console.log('dynamic4'); | ||
|
||
}); |
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/nested-dynamic-imports/_expected/amd/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
define(['require'], function (require) { 'use strict'; | ||
|
||
new Promise(function (resolve, reject) { require(['./generated-chunk.js'], resolve, reject) }); | ||
new Promise(function (resolve, reject) { require([('./generated-chunk.js')], resolve, reject) }); | ||
console.log('main'); | ||
|
||
}); |
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/preserve-modules-dynamic-imports/_expected/amd/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
define(['require'], function (require) { 'use strict'; | ||
|
||
new Promise(function (resolve, reject) { require(['./dynamic-included.js'], resolve, reject) }).then(result => console.log(result)); | ||
new Promise(function (resolve, reject) { require([('./dynamic-included.js')], resolve, reject) }).then(result => console.log(result)); | ||
|
||
}); |
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/sanitize-internal-exports/_expected/amd/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
test/function/samples/dynamic-import-name-warn/_expected/amd/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
define(['require'], function (require) { 'use strict'; | ||
|
||
new Promise(function (resolve, reject) { require(['./foo.js'], resolve, reject) }); | ||
new Promise(function (resolve, reject) { require([('./foo.js')], resolve, reject) }); | ||
|
||
}); |
2 changes: 1 addition & 1 deletion
2
test/function/samples/dynamic-import-name/_expected/amd/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
define(['require'], function (require) { 'use strict'; | ||
|
||
new Promise(function (resolve, reject) { require(['./foo.js'], resolve, reject) }); | ||
new Promise(function (resolve, reject) { require([('./foo.js')], resolve, reject) }); | ||
|
||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the initial version, this would also overwrite the opening
(
which enabled nicer output for AMD. There is actually a helper to detect substrings outside comments that could help you fix this:findFirstOccurrenceOutsideComment
inutils/renderHelpers.ts
. Here is how you could use it:Basically this function receives a string in which to search (which is usually
code.original
), a start index from which to search (this.parent.callee.end
is the latest I can think of), and a string to search for, and it will return the position in the string.With this change, no adaptions to the mechanisms should be necessary any more (unless I overlook something).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the feedback, i will update the PR! I was not very happy either with the:
require[('./generated.')]
But i was not able to find a better solution that didn't generate invalid JS