@@ -14,7 +14,7 @@ const assert = require('assert')
1414// Helpers
1515// ------------------------------------------------------------------------------
1616
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' ] )
1818const LT_CHAR = / [ \r \n \u2028 \u2029 ] /
1919const LINES = / [ ^ \r \n \u2028 \u2029 ] + (?: $ | \r \n | [ \r \n \u2028 \u2029 ] ) / g
2020const BLOCK_COMMENT_PREFIX = / ^ \s * \* /
@@ -205,6 +205,15 @@ function isNotEmptyTextNode (node) {
205205 return ! ( node . type === 'VText' && node . value . trim ( ) === '' )
206206}
207207
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+
208217/**
209218 * Get the last element.
210219 * @param {Array } xs The array to get the last element.
@@ -915,6 +924,34 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
915924 }
916925 } ,
917926
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+
918955 VForExpression ( node ) {
919956 const firstToken = tokenStore . getFirstToken ( node )
920957 const lastOfLeft = last ( node . left ) || firstToken
0 commit comments