@@ -681,15 +681,15 @@ module.exports = {
681
681
type : 'object' ,
682
682
key : prop . key ,
683
683
propName,
684
- value : unwrapTypes ( prop . value ) ,
684
+ value : skipTSAsExpression ( prop . value ) ,
685
685
node : prop
686
686
}
687
687
}
688
688
return {
689
689
type : 'object' ,
690
690
key : null ,
691
691
propName : null ,
692
- value : unwrapTypes ( prop . value ) ,
692
+ value : skipTSAsExpression ( prop . value ) ,
693
693
node : prop
694
694
}
695
695
} )
@@ -754,15 +754,15 @@ module.exports = {
754
754
type : 'object' ,
755
755
key : prop . key ,
756
756
emitName,
757
- value : unwrapTypes ( prop . value ) ,
757
+ value : skipTSAsExpression ( prop . value ) ,
758
758
node : prop
759
759
}
760
760
}
761
761
return {
762
762
type : 'object' ,
763
763
key : null ,
764
764
emitName : null ,
765
- value : unwrapTypes ( prop . value ) ,
765
+ value : skipTSAsExpression ( prop . value ) ,
766
766
node : prop
767
767
}
768
768
} )
@@ -823,7 +823,7 @@ module.exports = {
823
823
. map ( ( cp ) => {
824
824
const key = getStaticPropertyName ( cp )
825
825
/** @type {Expression } */
826
- const propValue = unwrapTypes ( cp . value )
826
+ const propValue = skipTSAsExpression ( cp . value )
827
827
/** @type {BlockStatement | null } */
828
828
let value = null
829
829
@@ -1017,7 +1017,7 @@ module.exports = {
1017
1017
const callee = callExpr . callee
1018
1018
1019
1019
if ( callee . type === 'MemberExpression' ) {
1020
- const calleeObject = unwrapTypes ( callee . object )
1020
+ const calleeObject = skipTSAsExpression ( callee . object )
1021
1021
1022
1022
if (
1023
1023
calleeObject . type === 'Identifier' &&
@@ -1271,11 +1271,11 @@ module.exports = {
1271
1271
getMemberChaining ( node ) {
1272
1272
/** @type {MemberExpression[] } */
1273
1273
const nodes = [ ]
1274
- let n = unwrapChainExpression ( node )
1274
+ let n = skipChainExpression ( node )
1275
1275
1276
1276
while ( n . type === 'MemberExpression' ) {
1277
1277
nodes . push ( n )
1278
- n = unwrapChainExpression ( n . object )
1278
+ n = skipChainExpression ( n . object )
1279
1279
}
1280
1280
1281
1281
return [ n , ...nodes . reverse ( ) ]
@@ -1339,24 +1339,17 @@ module.exports = {
1339
1339
*/
1340
1340
isPropertyChain,
1341
1341
/**
1342
- * Unwrap typescript types like "X as F"
1343
- * @template T
1344
- * @param {T } node
1345
- * @return {T }
1342
+ * Retrieve `TSAsExpression#expression` value if the given node a `TSAsExpression` node. Otherwise, pass through it.
1346
1343
*/
1347
- unwrapTypes ,
1344
+ skipTSAsExpression ,
1348
1345
/**
1349
- * Unwrap AssignmentPattern like "(a = 1) => ret"
1350
- * @param { AssignmentPattern | RestElement | ArrayPattern | ObjectPattern | Identifier } node
1351
- * @return { RestElement | ArrayPattern | ObjectPattern | Identifier }
1346
+ * Retrieve `AssignmentPattern#left` value if the given node a `AssignmentPattern` node. Otherwise, pass through it.
1352
1347
*/
1353
- unwrapAssignmentPattern ,
1348
+ skipDefaultParamValue ,
1354
1349
/**
1355
- * Unwrap ChainExpression like "(a?.b)"
1356
- * @param { Expression | Super } node
1357
- * @return { Expression | Super }
1350
+ * Retrieve `ChainExpression#expression` value if the given node a `ChainExpression` node. Otherwise, pass through it.
1358
1351
*/
1359
- unwrapChainExpression ,
1352
+ skipChainExpression ,
1360
1353
1361
1354
/**
1362
1355
* Check whether the given node is `this` or variable that stores `this`.
@@ -1617,20 +1610,21 @@ function isVElement(node) {
1617
1610
}
1618
1611
1619
1612
/**
1620
- * Unwrap typescript types like "X as F"
1621
- * @template T
1622
- * @param {T } node
1623
- * @return {T }
1613
+ * Retrieve `TSAsExpression#expression` value if the given node a `TSAsExpression` node. Otherwise, pass through it.
1614
+ * @template T Node type
1615
+ * @param {T | TSAsExpression } node The node to address.
1616
+ * @returns {T } The `TSAsExpression#expression` value if the node is a `TSAsExpression` node. Otherwise, the node.
1624
1617
*/
1625
- function unwrapTypes ( node ) {
1618
+ function skipTSAsExpression ( node ) {
1626
1619
if ( ! node ) {
1627
1620
return node
1628
1621
}
1629
1622
// @ts -expect-error
1630
1623
if ( node . type === 'TSAsExpression' ) {
1631
1624
// @ts -expect-error
1632
- return unwrapTypes ( node . expression )
1625
+ return skipTSAsExpression ( node . expression )
1633
1626
}
1627
+ // @ts -expect-error
1634
1628
return node
1635
1629
}
1636
1630
@@ -1661,36 +1655,40 @@ function isPropertyChain(prop, node) {
1661
1655
}
1662
1656
1663
1657
/**
1664
- * Unwrap AssignmentPattern like "(a = 1) => ret"
1665
- * @param { AssignmentPattern | RestElement | ArrayPattern | ObjectPattern | Identifier } node
1666
- * @return { RestElement | ArrayPattern | ObjectPattern | Identifier }
1658
+ * Retrieve `AssignmentPattern#left` value if the given node a `AssignmentPattern` node. Otherwise, pass through it.
1659
+ * @template T Node type
1660
+ * @param {T | AssignmentPattern } node The node to address.
1661
+ * @return {T } The `AssignmentPattern#left` value if the node is a `AssignmentPattern` node. Otherwise, the node.
1667
1662
*/
1668
- function unwrapAssignmentPattern ( node ) {
1663
+ function skipDefaultParamValue ( node ) {
1669
1664
if ( ! node ) {
1670
1665
return node
1671
1666
}
1667
+ // @ts -expect-error
1672
1668
if ( node . type === 'AssignmentPattern' ) {
1673
1669
// @ts -expect-error
1674
- return unwrapAssignmentPattern ( node . left )
1670
+ return skipDefaultParamValue ( node . left )
1675
1671
}
1672
+ // @ts -expect-error
1676
1673
return node
1677
1674
}
1678
1675
1679
1676
/**
1680
- * Unwrap ChainExpression like "(a?.b)"
1681
- * @template T
1682
- * @param {T } node
1683
- * @return {T }
1677
+ * Retrieve ` ChainExpression#expression` value if the given node a `ChainExpression` node. Otherwise, pass through it.
1678
+ * @template T Node type
1679
+ * @param {T | ChainExpression } node The node to address.
1680
+ * @returns {T } The `ChainExpression#expression` value if the node is a `ChainExpression` node. Otherwise, the node.
1684
1681
*/
1685
- function unwrapChainExpression ( node ) {
1682
+ function skipChainExpression ( node ) {
1686
1683
if ( ! node ) {
1687
1684
return node
1688
1685
}
1689
1686
// @ts -expect-error
1690
1687
if ( node . type === 'ChainExpression' ) {
1691
1688
// @ts -expect-error
1692
- return unwrapChainExpression ( node . expression )
1689
+ return skipChainExpression ( node . expression )
1693
1690
}
1691
+ // @ts -expect-error
1694
1692
return node
1695
1693
}
1696
1694
@@ -1792,7 +1790,7 @@ function isVueComponent(node) {
1792
1790
const callee = node . callee
1793
1791
1794
1792
if ( callee . type === 'MemberExpression' ) {
1795
- const calleeObject = unwrapTypes ( callee . object )
1793
+ const calleeObject = skipTSAsExpression ( callee . object )
1796
1794
1797
1795
if ( calleeObject . type === 'Identifier' ) {
1798
1796
const propName = getStaticPropertyName ( callee )
@@ -1846,7 +1844,8 @@ function isVueComponent(node) {
1846
1844
function isObjectArgument ( node ) {
1847
1845
return (
1848
1846
node . arguments . length > 0 &&
1849
- unwrapTypes ( node . arguments . slice ( - 1 ) [ 0 ] ) . type === 'ObjectExpression'
1847
+ skipTSAsExpression ( node . arguments . slice ( - 1 ) [ 0 ] ) . type ===
1848
+ 'ObjectExpression'
1850
1849
)
1851
1850
}
1852
1851
}
@@ -1864,7 +1863,7 @@ function isVueInstance(node) {
1864
1863
callee . type === 'Identifier' &&
1865
1864
callee . name === 'Vue' &&
1866
1865
node . arguments . length &&
1867
- unwrapTypes ( node . arguments [ 0 ] ) . type === 'ObjectExpression'
1866
+ skipTSAsExpression ( node . arguments [ 0 ] ) . type === 'ObjectExpression'
1868
1867
)
1869
1868
}
1870
1869
@@ -1884,21 +1883,24 @@ function getVueObjectType(context, node) {
1884
1883
const filePath = context . getFilename ( )
1885
1884
if (
1886
1885
isVueComponentFile ( parent , filePath ) &&
1887
- unwrapTypes ( parent . declaration ) === node
1886
+ skipTSAsExpression ( parent . declaration ) === node
1888
1887
) {
1889
1888
return 'export'
1890
1889
}
1891
1890
} else if ( parent . type === 'CallExpression' ) {
1892
1891
// Vue.component('xxx', {}) || component('xxx', {})
1893
1892
if (
1894
1893
isVueComponent ( parent ) &&
1895
- unwrapTypes ( parent . arguments . slice ( - 1 ) [ 0 ] ) === node
1894
+ skipTSAsExpression ( parent . arguments . slice ( - 1 ) [ 0 ] ) === node
1896
1895
) {
1897
1896
return 'definition'
1898
1897
}
1899
1898
} else if ( parent . type === 'NewExpression' ) {
1900
1899
// new Vue({})
1901
- if ( isVueInstance ( parent ) && unwrapTypes ( parent . arguments [ 0 ] ) === node ) {
1900
+ if (
1901
+ isVueInstance ( parent ) &&
1902
+ skipTSAsExpression ( parent . arguments [ 0 ] ) === node
1903
+ ) {
1902
1904
return 'instance'
1903
1905
}
1904
1906
}
0 commit comments