@@ -14,7 +14,7 @@ const assert = require('assert')
14
14
// Helpers
15
15
// ------------------------------------------------------------------------------
16
16
17
- const KNOWN_NODES = new Set ( [ 'ArrayExpression' , 'ArrayPattern' , 'ArrowFunctionExpression' , 'AssignmentExpression' , 'AssignmentPattern' , 'AwaitExpression' , 'BinaryExpression' , 'BlockStatement' , 'BreakStatement' , 'CallExpression' , 'CatchClause' , 'ClassBody' , 'ClassDeclaration' , 'ClassExpression' , 'ConditionalExpression' , 'ContinueStatement' , 'DebuggerStatement' , 'DoWhileStatement' , 'EmptyStatement' , 'ExperimentalRestProperty' , 'ExperimentalSpreadProperty' , 'ExportAllDeclaration' , 'ExportDefaultDeclaration' , 'ExportNamedDeclaration' , 'ExportSpecifier' , 'ExpressionStatement' , 'ForInStatement' , 'ForOfStatement' , 'ForStatement' , 'FunctionDeclaration' , 'FunctionExpression' , 'Identifier' , 'IfStatement' , 'ImportDeclaration' , 'ImportDefaultSpecifier' , 'ImportNamespaceSpecifier' , 'ImportSpecifier' , 'LabeledStatement' , 'Literal' , 'LogicalExpression' , 'MemberExpression' , 'MetaProperty' , 'MethodDefinition' , 'NewExpression' , 'ObjectExpression' , 'ObjectPattern' , 'Program' , 'Property' , 'RestElement' , 'ReturnStatement' , 'SequenceExpression' , 'SpreadElement' , 'Super' , 'SwitchCase' , 'SwitchStatement' , 'TaggedTemplateExpression' , 'TemplateElement' , 'TemplateLiteral' , 'ThisExpression' , 'ThrowStatement' , 'TryStatement' , 'UnaryExpression' , 'UpdateExpression' , 'VariableDeclaration' , 'VariableDeclarator' , 'WhileStatement' , 'WithStatement' , 'YieldExpression' , 'VAttribute' , 'VDirectiveKey' , 'VDocumentFragment' , 'VElement' , 'VEndTag' , 'VExpressionContainer' , 'VForExpression' , 'VIdentifier' , 'VLiteral' , 'VOnExpression' , 'VSlotScopeExpression' , 'VStartTag' , 'VText' ] )
17
+ const KNOWN_NODES = new Set ( [ 'ArrayExpression' , 'ArrayPattern' , 'ArrowFunctionExpression' , 'AssignmentExpression' , 'AssignmentPattern' , 'AwaitExpression' , 'BinaryExpression' , 'BlockStatement' , 'BreakStatement' , 'CallExpression' , 'CatchClause' , 'ClassBody' , 'ClassDeclaration' , 'ClassExpression' , 'ConditionalExpression' , 'ContinueStatement' , 'DebuggerStatement' , 'DoWhileStatement' , 'EmptyStatement' , 'ExperimentalRestProperty' , 'ExperimentalSpreadProperty' , 'ExportAllDeclaration' , 'ExportDefaultDeclaration' , 'ExportNamedDeclaration' , 'ExportSpecifier' , 'ExpressionStatement' , 'ForInStatement' , 'ForOfStatement' , 'ForStatement' , 'FunctionDeclaration' , 'FunctionExpression' , 'Identifier' , 'IfStatement' , 'ImportDeclaration' , 'ImportDefaultSpecifier' , 'ImportNamespaceSpecifier' , 'ImportSpecifier' , 'LabeledStatement' , 'Literal' , 'LogicalExpression' , 'MemberExpression' , 'MetaProperty' , 'MethodDefinition' , 'NewExpression' , 'ObjectExpression' , 'ObjectPattern' , 'Program' , 'Property' , 'RestElement' , 'ReturnStatement' , 'SequenceExpression' , 'SpreadElement' , 'Super' , 'SwitchCase' , 'SwitchStatement' , 'TaggedTemplateExpression' , 'TemplateElement' , 'TemplateLiteral' , 'ThisExpression' , 'ThrowStatement' , 'TryStatement' , 'UnaryExpression' , 'UpdateExpression' , 'VariableDeclaration' , 'VariableDeclarator' , 'WhileStatement' , 'WithStatement' , 'YieldExpression' , 'VAttribute' , 'VDirectiveKey' , 'VDocumentFragment' , 'VElement' , 'VEndTag' , 'VExpressionContainer' , 'VFilter' , 'VFilterSequenceExpression' , 'VForExpression' , 'VIdentifier' , 'VLiteral' , 'VOnExpression' , 'VSlotScopeExpression' , 'VStartTag' , 'VText' ] )
18
18
const LT_CHAR = / [ \r \n \u2028 \u2029 ] /
19
19
const LINES = / [ ^ \r \n \u2028 \u2029 ] + (?: $ | \r \n | [ \r \n \u2028 \u2029 ] ) / g
20
20
const BLOCK_COMMENT_PREFIX = / ^ \s * \* /
@@ -205,6 +205,15 @@ function isNotEmptyTextNode (node) {
205
205
return ! ( node . type === 'VText' && node . value . trim ( ) === '' )
206
206
}
207
207
208
+ /**
209
+ * Check whether the given token is a pipe operator.
210
+ * @param {Token } token The token to check.
211
+ * @returns {boolean } `true` if the token is a pipe operator.
212
+ */
213
+ function isPipeOperator ( token ) {
214
+ return token != null && token . type === 'Punctuator' && token . value === '|'
215
+ }
216
+
208
217
/**
209
218
* Get the last element.
210
219
* @param {Array } xs The array to get the last element.
@@ -915,6 +924,34 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
915
924
}
916
925
} ,
917
926
927
+ VFilter ( node ) {
928
+ const idToken = tokenStore . getFirstToken ( node )
929
+ const lastToken = tokenStore . getLastToken ( node )
930
+ if ( isRightParen ( lastToken ) ) {
931
+ const leftParenToken = tokenStore . getTokenAfter ( node . callee )
932
+ setOffset ( leftParenToken , 1 , idToken )
933
+ processNodeList ( node . arguments , leftParenToken , lastToken , 1 )
934
+ }
935
+ } ,
936
+
937
+ VFilterSequenceExpression ( node ) {
938
+ if ( node . filters . length === 0 ) {
939
+ return
940
+ }
941
+
942
+ const firstToken = tokenStore . getFirstToken ( node )
943
+ const tokens = [ ]
944
+
945
+ for ( const filter of node . filters ) {
946
+ tokens . push (
947
+ tokenStore . getTokenBefore ( filter , isPipeOperator ) ,
948
+ tokenStore . getFirstToken ( filter )
949
+ )
950
+ }
951
+
952
+ setOffset ( tokens , 1 , firstToken )
953
+ } ,
954
+
918
955
VForExpression ( node ) {
919
956
const firstToken = tokenStore . getFirstToken ( node )
920
957
const lastOfLeft = last ( node . left ) || firstToken
0 commit comments