Where can I view all the eslint ast node types? - abstract-syntax-tree

There are many node types to detect, ie:
VariableDeclarator
FunctionExpression
MemberExpression
AssignmentExpression
The eslint website explains the rules but doesn't provide all of the available node type detections.
I found a tutorial example detecting IfStatement but this is not picking up my if statement, so wondering if I have a syntax error.

Besides the ESTree documentation that you found, I would recommend: https://astexplorer.net/
It shows you the AST for the code you paste in and also highlights which part of the code each node corresponds to as you click/hover over them.
It's invaluable when writing a rule, figuring out edge cases, or in general, for understanding how the AST of a given snippet of code looks like. Give it a try!

A more up to date list (e.g., that includes ArrowFunctionExpression) is at https://github.com/benjamn/ast-types/blob/master/gen/namedTypes.ts . https://github.com/benjamn/ast-types/blob/master/gen/kinds.ts and https://github.com/benjamn/ast-types/blob/master/def/es6.ts are also interesting and may be helpful as well.

It's ok. The reason my ifstatement wasn't working was because i didn't have an if statement in the code I was testing.
Regarding the reference to all the ast node types I found that too -
https://github.com/estree/estree/blob/master/es5.md

I belive this is what you want
AssignmentExpression: [ 'left', 'right' ],
AssignmentPattern: [ 'left', 'right' ],
ArrayExpression: [ 'elements' ],
ArrayPattern: [ 'elements' ],
ArrowFunctionExpression: [ 'params', 'body' ],
AwaitExpression: [ 'argument' ],
BlockStatement: [ 'body' ],
BinaryExpression: [ 'left', 'right' ],
BreakStatement: [ 'label' ],
CallExpression: [ 'callee', 'arguments' ],
CatchClause: [ 'param', 'body' ],
ClassBody: [ 'body' ],
ClassDeclaration: [ 'id', 'superClass', 'body' ],
ClassExpression: [ 'id', 'superClass', 'body' ],
ConditionalExpression: [ 'test', 'consequent', 'alternate' ],
ContinueStatement: [ 'label' ],
DebuggerStatement: [],
DoWhileStatement: [ 'body', 'test' ],
EmptyStatement: [],
ExportAllDeclaration: [ 'source' ],
ExportDefaultDeclaration: [ 'declaration' ],
ExportNamedDeclaration: [ 'declaration', 'specifiers', 'source' ],
ExportSpecifier: [ 'exported', 'local' ],
ExpressionStatement: [ 'expression' ],
ExperimentalRestProperty: [ 'argument' ],
ExperimentalSpreadProperty: [ 'argument' ],
ForStatement: [ 'init', 'test', 'update', 'body' ],
ForInStatement: [ 'left', 'right', 'body' ],
ForOfStatement: [ 'left', 'right', 'body' ],
FunctionDeclaration: [ 'id', 'params', 'body' ],
FunctionExpression: [ 'id', 'params', 'body' ],
Identifier: [],
IfStatement: [ 'test', 'consequent', 'alternate' ],
ImportDeclaration: [ 'specifiers', 'source' ],
ImportDefaultSpecifier: [ 'local' ],
ImportExpression: [ 'source' ],
ImportNamespaceSpecifier: [ 'local' ],
ImportSpecifier: [ 'imported', 'local' ],
JSXAttribute: [ 'name', 'value' ],
JSXClosingElement: [ 'name' ],
JSXElement: [ 'openingElement', 'children', 'closingElement' ],
JSXEmptyExpression: [],
JSXExpressionContainer: [ 'expression' ],
JSXIdentifier: [],
JSXMemberExpression: [ 'object', 'property' ],
JSXNamespacedName: [ 'namespace', 'name' ],
JSXOpeningElement: [ 'name', 'attributes' ],
JSXSpreadAttribute: [ 'argument' ],
JSXText: [],
JSXFragment: [ 'openingFragment', 'children', 'closingFragment' ],
Literal: [],
LabeledStatement: [ 'label', 'body' ],
LogicalExpression: [ 'left', 'right' ],
MemberExpression: [ 'object', 'property' ],
MetaProperty: [ 'meta', 'property' ],
MethodDefinition: [ 'key', 'value' ],
NewExpression: [ 'callee', 'arguments' ],
ObjectExpression: [ 'properties' ],
ObjectPattern: [ 'properties' ],
Program: [ 'body' ],
Property: [ 'key', 'value' ],
RestElement: [ 'argument' ],
ReturnStatement: [ 'argument' ],
SequenceExpression: [ 'expressions' ],
SpreadElement: [ 'argument' ],
Super: [],
SwitchStatement: [ 'discriminant', 'cases' ],
SwitchCase: [ 'test', 'consequent' ],
TaggedTemplateExpression: [ 'tag', 'quasi' ],
TemplateElement: [],
TemplateLiteral: [ 'quasis', 'expressions' ],
ThisExpression: [],
ThrowStatement: [ 'argument' ],
TryStatement: [ 'block', 'handler', 'finalizer' ],
UnaryExpression: [ 'argument' ],
UpdateExpression: [ 'argument' ],
VariableDeclaration: [ 'declarations' ],
VariableDeclarator: [ 'id', 'init' ],
WhileStatement: [ 'test', 'body' ],
WithStatement: [ 'object', 'body' ],
YieldExpression: [ 'argument' ]

Related

GA4 Api - How to filter metrics with php library

I am trying to filter dimensions with the GA4 api php library. Unfortunately, it is still in beta and I can't find any php examples on how to filter dimensions.
My code returns "Expect Google\Analytics\Data\V1beta\NumericValue."
Any help would be appreciated.
$response = $client->runReport([
'property' => 'properties/' . $property_id,
'dateRanges' => [
new DateRange([
'start_date' => 'yesterday',
'end_date' => 'yesterday',
]),
],
'dimensions' => [
new Dimension([
'name' => 'eventName',
]),
],
'metrics' => [new Metric(
[
'name' => 'eventCount',
])
],
'metricFilter' => new FilterExpression([
'filter' => new Filter([
'field_name' => 'eventCount',
'numeric_filter' => new Filter\NumericFilter([
'operation' => Filter\NumericFilter\Operation::GREATER_THAN,
'value' => '10000',
])
]),
]),
]);
Here is the JSON version of the request from the api explorer:
{
"dimensions": [
{
"name": "eventName"
}
],
"metrics": [
{
"name": "eventCount"
}
],
"dateRanges": [
{
"startDate": "yesterday",
"endDate": "yesterday"
}
],
"metricFilter": {
"filter": {
"fieldName": "eventCount",
"numericFilter": {
"operation": "GREATER_THAN",
"value": {
"int64Value": "10000"
}
}
}
}
}
I found the solution, I decided to leave this post since there is very little out there about filtering the ga4 api.
'metricFilter' => new FilterExpression([
'filter' => new Filter([
'field_name' => 'eventCount',
'numeric_filter' => new Filter\NumericFilter([
'operation' => Filter\NumericFilter\Operation::GREATER_THAN,
'value' => new NumericValue([
'int64_value' => '10000'
]),
])
]),
]),
```

FacetWP, query from today's date

i'm looking for a way to query posts with a date from today (current day).
My query looks like that :
<?php
return [
"post_type" => [
"event"
],
"post_status" => [
"publish"
],
"meta_query" => [
"0" => [
"key" => "date",
"compare" => ">",
"type" => "DECIMAL(16,4)",
"value" => "XXXXX"
],
"sort_0" => [
"key" => "date",
"type" => "CHAR"
]
],
"orderby" => [
"sort_0" => "ASC"
],
"posts_per_page" => "4"
];
I don't know what to set on TYPE and VALUE.
Is this possible to help me please?
Thanks a lot.
Actually I found out how to do it :)
Here is the snippet I should have used :
<?php
return [
"post_type" => [
"event"
],
"post_status" => [
"publish"
],
"meta_query" => [
"sort_0" => [
"key" => "date",
"compare" => ">",
"type" => "DATE",
"value" => date("Y-m-d"),
]
],
"orderby" => [
"sort_0" => "ASC"
],
"posts_per_page" => "4"
];

How to use match_phrase with constant_score, terms

This is my query in symfony2. I want to add here "match_phrase", but anywhere i add that, I get errors.
$params = [
'index' => 'articles_v2',
'type' => 'article',
'body' => [
"sort" => [
[ "date" =>
["order" => "desc"]
],
],
"from" => $fromId,
"size" => $newsPerPage,
"query" => [
"constant_score" => [
"filter" => [
"bool" => [
"must" => [
["terms" => [ "article.topics" => $topics ] ],
["match_phrase" => ["article.bodytext" => [$search_phrase] ]]
]
]
]
]
]
]
];
$response = $client->search($params);
When I try to run this, I get error:
nested: QueryParsingException[[articles_v2] No filter registered for [match_phrase]]; }]","status":400
So where to place this match_phrase?
(I want to get results like SQL LIKE '%xxxx%')
I have changed the query. this time no errors, but anyway, no filtration.
$params = [
'index' => 'articles_v2',
'type' => 'article',
'body' => [
"sort" => [
[ "date" =>
["order" => "desc"]
],
],
"from" => $fromId,
"size" => $newsPerPage,
"query" => [
"constant_score" => [
"filter" => [
"bool" => [
"must" => [
["terms" => [ "article.topics" => $topics ] ]
]
]
],
"query" => [
"multi_match" => [
"query" => $search_phrase,
"fields" => [ "title", "bodytext" ]
]
]
]
]
]
];
$response = $client->search($params);
The solution is not to use match with constant score.
You have to use query/bool/must and all this match and other conditions inside must.
Here is the code.
$params = [
'index' => 'articles_v2',
'type' => 'article',
'size' => 50,
'body' => [
"sort" => [
[ "date" =>
["order" => "desc"]
],
],
"from" => $fromId,
"size" => $newsPerPage,
"query" => [
"bool" => [
"must" => [
[
"match_phrase_prefix" => [
"_all" => [
"query" => $search_phrase,
"operator" => "and",
"analyzer" => "analyzer_cs"
]
]
],
["terms" => [ "article.topics" => $topics ] ],
["range" => [ "article.date" => [ "from" => $date_from,"to" => $date_till]]]
]
]
]
]
];

DynamoDB - Update item by GSI (PHP)

I'm trying to update an item using a Global Secondary Index. My table definition is listed below. I am new to DynamoDb.
$response = $this->client->createTable([
'TableName' => 'rawproducts_products',
'AttributeDefinitions' => [
[
'AttributeName' => 'product_code',
'AttributeType' => 'N'
],
[
'AttributeName' => 'token',
'AttributeType' => 'S'
],
[
'AttributeName' => 'processed_at',
'AttributeType' => 'N'
],
[
'AttributeName' => 'created_at',
'AttributeType' => 'N'
]
],
'KeySchema' => [
[
'AttributeName' => 'product_code',
'KeyType' => 'HASH'
],
[
'AttributeName' => 'token',
'KeyType' => 'RANGE'
]
],
'LocalSecondaryIndexes' => [
[
'IndexName' => 'ProductCodeProcessedIndex',
'KeySchema' => [
['AttributeName' => 'product_code', 'KeyType' => 'HASH'],
['AttributeName' => 'processed_at', 'KeyType' => 'RANGE']
],
'Projection' => [
'ProjectionType' => 'KEYS_ONLY',
],
],
[
'IndexName' => 'ProductCodeCreatedIndex',
'KeySchema' => [
['AttributeName' => 'product_code', 'KeyType' => 'HASH'],
['AttributeName' => 'created_at', 'KeyType' => 'RANGE']
],
'Projection' => [
'ProjectionType' => 'KEYS_ONLY',
],
]
],
'GlobalSecondaryIndexes' => [
[
'IndexName' => 'TokenIndex',
'KeySchema' => [
[ 'AttributeName' => 'token', 'KeyType' => 'HASH' ]
],
'Projection' => [
'ProjectionType' => 'ALL'
],
'ProvisionedThroughput' => [
'ReadCapacityUnits' => 1, 'WriteCapacityUnits' => 1
]
]
],
'ProvisionedThroughput' => [
'ReadCapacityUnits' => 5,
'WriteCapacityUnits' => 6
]
]);
When I try to update the attribute "complete" using the query below:
$this->dynamoDb->updateItem([
'TableName' => $this->table,
'TableIndex' => 'TokenIndex',
'Key' => [
'token' => ['S' => (string)$this->token['S']]
],
'UpdateExpression' => 'set complete = :complete',
'ExpressionAttributeValues' => [
':complete' => ['N' => (string)1]
]
]);
But I keep getting the following error:
"The provided key element does not match the schema"
Can anybody please advise a newbie. Many thanks.
It shows this because you are not passing key properly
You need to pass product_code and token both to update the value
Secondly
You cannot update value directly from GSI it's just a projection of the Table and not actual table
If you want to update the value you have to update in the table not in the index
refer this link.

How to read external GeoJSON file from openlayers?

I have to draw some lines by OpenLayers. The line features are coded as GeoJSON format. My code is ok for hard coded GeoJSON features. But, if I put this features in separate file and try to load it. It just does not work. I do not know what is the wrong with my loading external GeoJSON file. I have given both the code.
Code 1:
// This code is ok with hard coded GeoJSON features
map.addControl(new OpenLayers.Control.LayerSwitcher());
vectorLayer = new OpenLayers.Layer.Vector("Lines");
var myGeoJSON = { "type": "FeatureCollection",
"features":
[
{ "type": "Feature", "properties": { "LENGTH": 756.304000}, "geometry": { "type": "LineString", "coordinates": [ [ 18.105018, 59.231027 ], [ 18.104176, 59.230737 ], [ 18.103928, 59.230415 ], [ 18.103650, 59.230336 ], [ 18.103028, 59.230463 ], [ 18.102491, 59.230418 ], [ 18.101976, 59.230237 ], [ 18.100893, 59.230110 ], [ 18.100117, 59.230016 ], [ 18.097715, 59.230262 ], [ 18.096907, 59.230376 ], [ 18.096637, 59.230405 ], [ 18.096578, 59.230428 ], [ 18.096429, 59.230450 ], [ 18.096336, 59.230479 ], [ 18.096108, 59.230534 ], [ 18.095971, 59.230600 ], [ 18.095925, 59.230633 ], [ 18.095891, 59.230665 ], [ 18.094000, 59.231676 ], [ 18.093864, 59.231720 ] ] } }
,
{ "type": "Feature", "properties": { "LENGTH": 1462.390000}, "geometry": { "type": "LineString", "coordinates": [ [ 17.877073, 59.461653 ], [ 17.877116, 59.461598 ], [ 17.876936, 59.461507 ], [ 17.876936, 59.461323 ], [ 17.876773, 59.461098 ], [ 17.876430, 59.460885 ], [ 17.876413, 59.460553 ], [ 17.876576, 59.460280 ], [ 17.876575, 59.460078 ], [ 17.876762, 59.460060 ], [ 17.877371, 59.460042 ], [ 17.877808, 59.460046 ], [ 17.878641, 59.460046 ], [ 17.879010, 59.460078 ], [ 17.879337, 59.460044 ], [ 17.879526, 59.459878 ], [ 17.879749, 59.459563 ], [ 17.880058, 59.459538 ], [ 17.880435, 59.459503 ], [ 17.887550, 59.453608 ], [ 17.887696, 59.453430 ], [ 17.887971, 59.453150 ], [ 17.888221, 59.452843 ], [ 17.888246, 59.452721 ], [ 17.888435, 59.452609 ], [ 17.888470, 59.452568 ], [ 17.888517, 59.452410 ] ] } }
]
};
var geojson_format = new OpenLayers.Format.GeoJSON({
'internalProjection': map.baseLayer.projection,
'externalProjection': new OpenLayers.Projection("EPSG:4326")
});
map.addLayer(vectorLayer);
vectorLayer.addFeatures(geojson_format.read(myGeoJSON));
map.setCenter(
new OpenLayers.LonLat(18.068611, 59.329444).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
), 10
);
Code 2: This code shows an error that it could not load features
//This code does not work because it can not load the external GeoJSON file
map.addControl(new OpenLayers.Control.LayerSwitcher());
vectorLayer = new OpenLayers.Layer.Vector("Lines");
var myGeoJSON = new OpenLayers.Layer.Vector("Lines", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: "ml/lines.json"
})
});
var geojson_format = new OpenLayers.Format.GeoJSON({
'internalProjection': map.baseLayer.projection,
'externalProjection': new OpenLayers.Projection("EPSG:4326")
});
map.addLayer(vectorLayer);
vectorLayer.addFeatures(geojson_format.read(myGeoJSON));
map.setCenter(
new OpenLayers.LonLat(18.068611, 59.329444).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
), 10
);
Thanks in advance
geojson_layer = new OpenLayers.Layer.Vector("GeoJSON", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: "ml/lines.json",
format: new OpenLayers.Format.GeoJSON()
})
});
See my little example.

Resources