File tree Expand file tree Collapse file tree
test/configCases/parsing/import-meta-computed Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ " webpack " : patch
3+ ---
4+
5+ Support no-expression template literals in computed member access for ` import.meta ` .
Original file line number Diff line number Diff line change @@ -4102,10 +4102,7 @@ class JavascriptParser extends Parser {
41024102 if ( expression . object . type === "MemberExpression" ) {
41034103 // optimize the case where expression.object is a MemberExpression too.
41044104 // we can keep info here when calling walkMemberExpression directly
4105- const property =
4106- /** @type {Identifier } */
4107- ( expression . property ) . name ||
4108- `${ /** @type {Literal } */ ( expression . property ) . value } ` ;
4105+ const property = members [ members . length - 1 ] ;
41094106 name = name . slice ( 0 , - property . length - 1 ) ;
41104107 members . pop ( ) ;
41114108 const result = this . callHooksForInfo (
@@ -5223,9 +5220,10 @@ class JavascriptParser extends Parser {
52235220 const memberRanges = [ ] ;
52245221 while ( expr . type === "MemberExpression" ) {
52255222 if ( expr . computed ) {
5226- if ( expr . property . type !== "Literal" ) break ;
5227- members . push ( `${ expr . property . value } ` ) ; // the literal
5228- memberRanges . push ( /** @type {Range } */ ( expr . object . range ) ) ; // the range of the expression fragment before the literal
5223+ const member = this . evaluateExpression ( expr . property ) . asString ( ) ;
5224+ if ( typeof member !== "string" ) break ;
5225+ members . push ( member ) ;
5226+ memberRanges . push ( /** @type {Range } */ ( expr . object . range ) ) ;
52295227 } else {
52305228 if ( expr . property . type !== "Identifier" ) break ;
52315229 members . push ( expr . property . name ) ; // the identifier
Original file line number Diff line number Diff line change 1+ it ( "should support computed property access with literal string on import.meta" , ( ) => {
2+ const url = import . meta. url ;
3+ expect ( import . meta[ "url" ] ) . toBe ( url ) ;
4+ } ) ;
5+
6+ it ( "should support computed property access with template string on import.meta" , ( ) => {
7+ const url = import . meta. url ;
8+ expect ( import . meta[ `url` ] ) . toBe ( url ) ;
9+ } ) ;
10+
11+ it ( "should support computed property access with string concatenation on import.meta" , ( ) => {
12+ const url = import . meta. url ;
13+ expect ( import . meta[ "u" + "rl" ] ) . toBe ( url ) ;
14+ } ) ;
15+
16+ it ( "should support computed property access on import.meta.webpackHot" , ( ) => {
17+ if ( import . meta. webpackHot ) {
18+ expect ( import . meta[ "webpackHot" ] ) . toBe ( import . meta. webpackHot ) ;
19+ }
20+ } ) ;
Original file line number Diff line number Diff line change 1+ "use strict" ;
2+
3+ /** @type {import("../../../../types").Configuration } */
4+ module . exports = {
5+ mode : "development" ,
6+ devtool : false ,
7+ target : "node"
8+ } ;
You can’t perform that action at this time.
0 commit comments