@@ -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
} )
@@ -752,15 +752,15 @@ module.exports = {
752
752
type : 'object' ,
753
753
key : prop . key ,
754
754
emitName,
755
- value : unwrapTypes ( prop . value ) ,
755
+ value : skipTSAsExpression ( prop . value ) ,
756
756
node : prop
757
757
}
758
758
}
759
759
return {
760
760
type : 'object' ,
761
761
key : null ,
762
762
emitName : null ,
763
- value : unwrapTypes ( prop . value ) ,
763
+ value : skipTSAsExpression ( prop . value ) ,
764
764
node : prop
765
765
}
766
766
} )
@@ -819,7 +819,7 @@ module.exports = {
819
819
. map ( ( cp ) => {
820
820
const key = getStaticPropertyName ( cp )
821
821
/** @type {Expression } */
822
- const propValue = unwrapTypes ( cp . value )
822
+ const propValue = skipTSAsExpression ( cp . value )
823
823
/** @type {BlockStatement | null } */
824
824
let value = null
825
825
@@ -1013,7 +1013,7 @@ module.exports = {
1013
1013
const callee = callExpr . callee
1014
1014
1015
1015
if ( callee . type === 'MemberExpression' ) {
1016
- const calleeObject = unwrapTypes ( callee . object )
1016
+ const calleeObject = skipTSAsExpression ( callee . object )
1017
1017
1018
1018
if (
1019
1019
calleeObject . type === 'Identifier' &&
@@ -1270,11 +1270,11 @@ module.exports = {
1270
1270
getMemberChaining ( node ) {
1271
1271
/** @type {MemberExpression[] } */
1272
1272
const nodes = [ ]
1273
- let n = unwrapChainExpression ( node )
1273
+ let n = skipChainExpression ( node )
1274
1274
1275
1275
while ( n . type === 'MemberExpression' ) {
1276
1276
nodes . push ( n )
1277
- n = unwrapChainExpression ( n . object )
1277
+ n = skipChainExpression ( n . object )
1278
1278
}
1279
1279
1280
1280
return [ n , ...nodes . reverse ( ) ]
@@ -1338,24 +1338,17 @@ module.exports = {
1338
1338
*/
1339
1339
isPropertyChain,
1340
1340
/**
1341
- * Unwrap typescript types like "X as F"
1342
- * @template T
1343
- * @param {T } node
1344
- * @return {T }
1341
+ * Retrieve `TSAsExpression#expression` value if the given node a `TSAsExpression` node. Otherwise, pass through it.
1345
1342
*/
1346
- unwrapTypes ,
1343
+ skipTSAsExpression ,
1347
1344
/**
1348
- * Unwrap AssignmentPattern like "(a = 1) => ret"
1349
- * @param { AssignmentPattern | RestElement | ArrayPattern | ObjectPattern | Identifier } node
1350
- * @return { RestElement | ArrayPattern | ObjectPattern | Identifier }
1345
+ * Retrieve `AssignmentPattern#left` value if the given node a `AssignmentPattern` node. Otherwise, pass through it.
1351
1346
*/
1352
- unwrapAssignmentPattern ,
1347
+ skipDefaultParamValue ,
1353
1348
/**
1354
- * Unwrap ChainExpression like "(a?.b)"
1355
- * @param { Expression | Super } node
1356
- * @return { Expression | Super }
1349
+ * Retrieve `ChainExpression#expression` value if the given node a `ChainExpression` node. Otherwise, pass through it.
1357
1350
*/
1358
- unwrapChainExpression ,
1351
+ skipChainExpression ,
1359
1352
1360
1353
/**
1361
1354
* Check whether the given node is `this` or variable that stores `this`.
@@ -1651,20 +1644,21 @@ function isVElement(node) {
1651
1644
}
1652
1645
1653
1646
/**
1654
- * Unwrap typescript types like "X as F"
1655
- * @template T
1656
- * @param {T } node
1657
- * @return {T }
1647
+ * Retrieve `TSAsExpression#expression` value if the given node a `TSAsExpression` node. Otherwise, pass through it.
1648
+ * @template T Node type
1649
+ * @param {T | TSAsExpression } node The node to address.
1650
+ * @returns {T } The `TSAsExpression#expression` value if the node is a `TSAsExpression` node. Otherwise, the node.
1658
1651
*/
1659
- function unwrapTypes ( node ) {
1652
+ function skipTSAsExpression ( node ) {
1660
1653
if ( ! node ) {
1661
1654
return node
1662
1655
}
1663
1656
// @ts -expect-error
1664
1657
if ( node . type === 'TSAsExpression' ) {
1665
1658
// @ts -expect-error
1666
- return unwrapTypes ( node . expression )
1659
+ return skipTSAsExpression ( node . expression )
1667
1660
}
1661
+ // @ts -expect-error
1668
1662
return node
1669
1663
}
1670
1664
@@ -1695,36 +1689,40 @@ function isPropertyChain(prop, node) {
1695
1689
}
1696
1690
1697
1691
/**
1698
- * Unwrap AssignmentPattern like "(a = 1) => ret"
1699
- * @param { AssignmentPattern | RestElement | ArrayPattern | ObjectPattern | Identifier } node
1700
- * @return { RestElement | ArrayPattern | ObjectPattern | Identifier }
1692
+ * Retrieve `AssignmentPattern#left` value if the given node a `AssignmentPattern` node. Otherwise, pass through it.
1693
+ * @template T Node type
1694
+ * @param {T | AssignmentPattern } node The node to address.
1695
+ * @return {T } The `AssignmentPattern#left` value if the node is a `AssignmentPattern` node. Otherwise, the node.
1701
1696
*/
1702
- function unwrapAssignmentPattern ( node ) {
1697
+ function skipDefaultParamValue ( node ) {
1703
1698
if ( ! node ) {
1704
1699
return node
1705
1700
}
1701
+ // @ts -expect-error
1706
1702
if ( node . type === 'AssignmentPattern' ) {
1707
1703
// @ts -expect-error
1708
- return unwrapAssignmentPattern ( node . left )
1704
+ return skipDefaultParamValue ( node . left )
1709
1705
}
1706
+ // @ts -expect-error
1710
1707
return node
1711
1708
}
1712
1709
1713
1710
/**
1714
- * Unwrap ChainExpression like "(a?.b)"
1715
- * @template T
1716
- * @param {T } node
1717
- * @return {T }
1711
+ * Retrieve ` ChainExpression#expression` value if the given node a `ChainExpression` node. Otherwise, pass through it.
1712
+ * @template T Node type
1713
+ * @param {T | ChainExpression } node The node to address.
1714
+ * @returns {T } The `ChainExpression#expression` value if the node is a `ChainExpression` node. Otherwise, the node.
1718
1715
*/
1719
- function unwrapChainExpression ( node ) {
1716
+ function skipChainExpression ( node ) {
1720
1717
if ( ! node ) {
1721
1718
return node
1722
1719
}
1723
1720
// @ts -expect-error
1724
1721
if ( node . type === 'ChainExpression' ) {
1725
1722
// @ts -expect-error
1726
- return unwrapChainExpression ( node . expression )
1723
+ return skipChainExpression ( node . expression )
1727
1724
}
1725
+ // @ts -expect-error
1728
1726
return node
1729
1727
}
1730
1728
@@ -1826,7 +1824,7 @@ function isVueComponent(node) {
1826
1824
const callee = node . callee
1827
1825
1828
1826
if ( callee . type === 'MemberExpression' ) {
1829
- const calleeObject = unwrapTypes ( callee . object )
1827
+ const calleeObject = skipTSAsExpression ( callee . object )
1830
1828
1831
1829
if ( calleeObject . type === 'Identifier' ) {
1832
1830
const propName = getStaticPropertyName ( callee )
@@ -1880,7 +1878,8 @@ function isVueComponent(node) {
1880
1878
function isObjectArgument ( node ) {
1881
1879
return (
1882
1880
node . arguments . length > 0 &&
1883
- unwrapTypes ( node . arguments . slice ( - 1 ) [ 0 ] ) . type === 'ObjectExpression'
1881
+ skipTSAsExpression ( node . arguments . slice ( - 1 ) [ 0 ] ) . type ===
1882
+ 'ObjectExpression'
1884
1883
)
1885
1884
}
1886
1885
}
@@ -1898,7 +1897,7 @@ function isVueInstance(node) {
1898
1897
callee . type === 'Identifier' &&
1899
1898
callee . name === 'Vue' &&
1900
1899
node . arguments . length &&
1901
- unwrapTypes ( node . arguments [ 0 ] ) . type === 'ObjectExpression'
1900
+ skipTSAsExpression ( node . arguments [ 0 ] ) . type === 'ObjectExpression'
1902
1901
)
1903
1902
}
1904
1903
@@ -1918,21 +1917,24 @@ function getVueObjectType(context, node) {
1918
1917
const filePath = context . getFilename ( )
1919
1918
if (
1920
1919
isVueComponentFile ( parent , filePath ) &&
1921
- unwrapTypes ( parent . declaration ) === node
1920
+ skipTSAsExpression ( parent . declaration ) === node
1922
1921
) {
1923
1922
return 'export'
1924
1923
}
1925
1924
} else if ( parent . type === 'CallExpression' ) {
1926
1925
// Vue.component('xxx', {}) || component('xxx', {})
1927
1926
if (
1928
1927
isVueComponent ( parent ) &&
1929
- unwrapTypes ( parent . arguments . slice ( - 1 ) [ 0 ] ) === node
1928
+ skipTSAsExpression ( parent . arguments . slice ( - 1 ) [ 0 ] ) === node
1930
1929
) {
1931
1930
return 'definition'
1932
1931
}
1933
1932
} else if ( parent . type === 'NewExpression' ) {
1934
1933
// new Vue({})
1935
- if ( isVueInstance ( parent ) && unwrapTypes ( parent . arguments [ 0 ] ) === node ) {
1934
+ if (
1935
+ isVueInstance ( parent ) &&
1936
+ skipTSAsExpression ( parent . arguments [ 0 ] ) === node
1937
+ ) {
1936
1938
return 'instance'
1937
1939
}
1938
1940
}
0 commit comments