@@ -1265,4 +1265,118 @@ describe('JavaScript parser', () => {
12651265 ) ;
12661266 } ) ;
12671267 } ) ;
1268+
1269+ describe ( 'computed method name extraction (#1471)' , ( ) => {
1270+ it ( 'extracts computed getter method from object literal' , ( ) => {
1271+ const symbols = parseJS ( `const obj = { get ['property7']() {} };` ) ;
1272+ expect ( symbols . definitions ) . toContainEqual (
1273+ expect . objectContaining ( { name : "['property7']" , kind : 'method' } ) ,
1274+ ) ;
1275+ } ) ;
1276+
1277+ it ( 'extracts computed setter method with parameter from object literal' , ( ) => {
1278+ const symbols = parseJS ( `const obj = { set ['property8'](value) {} };` ) ;
1279+ const def = symbols . definitions . find ( ( d ) => d . name === "['property8']" ) ;
1280+ expect ( def ) . toBeDefined ( ) ;
1281+ expect ( def ) . toMatchObject ( { kind : 'method' } ) ;
1282+ expect ( def ! . children ) . toContainEqual (
1283+ expect . objectContaining ( { name : 'value' , kind : 'parameter' } ) ,
1284+ ) ;
1285+ } ) ;
1286+
1287+ it ( 'extracts computed regular method with parameter from object literal' , ( ) => {
1288+ const symbols = parseJS ( `const obj = { ['property9'](parameters) {} };` ) ;
1289+ const def = symbols . definitions . find ( ( d ) => d . name === "['property9']" ) ;
1290+ expect ( def ) . toBeDefined ( ) ;
1291+ expect ( def ! . children ) . toContainEqual (
1292+ expect . objectContaining ( { name : 'parameters' , kind : 'parameter' } ) ,
1293+ ) ;
1294+ } ) ;
1295+
1296+ it ( 'extracts computed generator method from object literal' , ( ) => {
1297+ const symbols = parseJS ( `const obj = { *['generator10'](parameters) {} };` ) ;
1298+ expect ( symbols . definitions ) . toContainEqual (
1299+ expect . objectContaining ( { name : "['generator10']" , kind : 'method' } ) ,
1300+ ) ;
1301+ } ) ;
1302+
1303+ it ( 'extracts computed async method from object literal' , ( ) => {
1304+ const symbols = parseJS ( `const obj = { async ['property11'](parameters) {} };` ) ;
1305+ expect ( symbols . definitions ) . toContainEqual (
1306+ expect . objectContaining ( { name : "['property11']" , kind : 'method' } ) ,
1307+ ) ;
1308+ } ) ;
1309+ } ) ;
1310+
1311+ describe ( 'class expression inside function extraction (#1471)' , ( ) => {
1312+ it ( 'extracts named class expression returned from a function' , ( ) => {
1313+ const symbols = parseJS (
1314+ `function mixin() { return class PostMixin extends A { constructor() { super(); } }; }` ,
1315+ ) ;
1316+ expect ( symbols . definitions ) . toContainEqual (
1317+ expect . objectContaining ( { name : 'PostMixin' , kind : 'class' } ) ,
1318+ ) ;
1319+ } ) ;
1320+
1321+ it ( 'records extends relationship for class expression inside function' , ( ) => {
1322+ const symbols = parseJS ( `function mixin() { return class PostMixin extends A { m() {} }; }` ) ;
1323+ expect ( symbols . classes ) . toContainEqual (
1324+ expect . objectContaining ( { name : 'PostMixin' , extends : 'A' } ) ,
1325+ ) ;
1326+ } ) ;
1327+
1328+ it ( 'extracts class field properties as children of class expression' , ( ) => {
1329+ const symbols = parseJS (
1330+ `function mixin() { return class PostMixin extends A { w = 1; eee = this; }; }` ,
1331+ ) ;
1332+ const pm = symbols . definitions . find ( ( d ) => d . name === 'PostMixin' ) ;
1333+ expect ( pm ) . toBeDefined ( ) ;
1334+ expect ( pm ! . children ) . toContainEqual ( expect . objectContaining ( { name : 'w' , kind : 'property' } ) ) ;
1335+ expect ( pm ! . children ) . toContainEqual (
1336+ expect . objectContaining ( { name : 'eee' , kind : 'property' } ) ,
1337+ ) ;
1338+ } ) ;
1339+ } ) ;
1340+
1341+ describe ( 'array destructuring constant extraction (#1471)' , ( ) => {
1342+ it ( 'extracts const array pattern as a single constant node' , ( ) => {
1343+ const symbols = parseJS ( `const [x, y] = new Set([() => {}, () => {}]);` ) ;
1344+ expect ( symbols . definitions ) . toContainEqual (
1345+ expect . objectContaining ( { name : '[x, y]' , kind : 'constant' } ) ,
1346+ ) ;
1347+ } ) ;
1348+
1349+ it ( 'does not extract let or var array destructuring' , ( ) => {
1350+ const symbols = parseJS ( `let [a, b] = [1, 2];` ) ;
1351+ expect ( symbols . definitions . every ( ( d ) => d . name !== '[a, b]' ) ) . toBe ( true ) ;
1352+ } ) ;
1353+ } ) ;
1354+
1355+ describe ( 'prototype method parameter extraction (#1471)' , ( ) => {
1356+ it ( 'extracts parameters from Foo.prototype.bar = (x, y) => arrow' , ( ) => {
1357+ const symbols = parseJS ( `function Arit() {}\nArit.prototype.sum = (x, y) => x + y;` ) ;
1358+ const def = symbols . definitions . find ( ( d ) => d . name === 'Arit.sum' ) ;
1359+ expect ( def ) . toBeDefined ( ) ;
1360+ expect ( def ! . children ) . toContainEqual (
1361+ expect . objectContaining ( { name : 'x' , kind : 'parameter' } ) ,
1362+ ) ;
1363+ expect ( def ! . children ) . toContainEqual (
1364+ expect . objectContaining ( { name : 'y' , kind : 'parameter' } ) ,
1365+ ) ;
1366+ } ) ;
1367+
1368+ it ( 'extracts parameters from Foo.prototype.bar = function(key, value)' , ( ) => {
1369+ const symbols = parseJS (
1370+ `function Foo() {}\nFoo.prototype.add = function(key, value) { this[key] = value; };` ,
1371+ ) ;
1372+ const def = symbols . definitions . find ( ( d ) => d . name === 'Foo.add' ) ;
1373+ expect ( def ) . toBeDefined ( ) ;
1374+ expect ( def ! . children ) . toContainEqual (
1375+ expect . objectContaining ( { name : 'key' , kind : 'parameter' } ) ,
1376+ ) ;
1377+ expect ( def ! . children ) . toContainEqual (
1378+ expect . objectContaining ( { name : 'value' , kind : 'parameter' } ) ,
1379+ ) ;
1380+ } ) ;
1381+ } ) ;
12681382} ) ;
0 commit comments