Skip to content

Commit 827578f

Browse files
Update example UDF to ES6 syntax and remove related warning (#9123)
## Description Update example UDF to ES6 syntax and remove related warning Google-provided Dataflow templates have supported ES6 syntax since the 2023-01-03 release (see [notes](https://cloud.google.com/dataflow/docs/release-notes#January_03_2023)). ## Checklist - [ ] I have followed [Sample Guidelines from AUTHORING_GUIDE.MD](https://togithub.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md) - [ ] README is updated to include [all relevant information](https://togithub.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md#readme-file) - [ ] **Tests** pass: `nox -s py-3.9` (see [Test Environment Setup](https://togithub.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md#test-environment-setup)) - [ ] **Lint** pass: `nox -s lint` (see [Test Environment Setup](https://togithub.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md#test-environment-setup)) - [ ] These samples need a new **API enabled** in testing projects to pass (let us know which ones) - [ ] These samples need a new/updated **env vars** in testing projects set to pass (let us know which ones) - [ ] Please **merge** this PR for me once it is approved. - [ ] This sample adds a new sample directory, and I updated the [CODEOWNERS file](https://togithub.com/GoogleCloudPlatform/python-docs-samples/blob/main/.github/CODEOWNERS) with the codeowners for this sample
1 parent f23eb84 commit 827578f

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

dataflow/extensible-templates/dataflow_udf_transform.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020
* @param {string} inJson input Pub/Sub JSON message (stringified)
2121
*/
2222
function process(inJson) {
23-
// Nashorn engine is only ECMAScript 5.1 (ES5) compliant. Newer ES6
24-
// JavaScript keywords like `let` or `const` will cause syntax errors.
25-
var obj = JSON.parse(inJson);
26-
var includePubsubMessage = obj.data && obj.attributes;
27-
var data = includePubsubMessage ? obj.data : obj;
23+
const obj = JSON.parse(inJson);
24+
const includePubsubMessage = obj.data && obj.attributes;
25+
const data = includePubsubMessage ? obj.data : obj;
2826

2927
if (!data.hasOwnProperty('url')) {
3028
throw new Error("No url found");

0 commit comments

Comments
 (0)