Skip to content

Commit

Permalink
MAINT Replace var ==> let and added semicolons (pyodide#979)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hood Chatham authored Jan 13, 2021
1 parent 170c52d commit 40bd093
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion docs/js-api/pyodide_pyimport.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Access a Python object in the global namespace from Javascript.

For example, to access the `foo` Python object from Javascript:
```javascript
var foo = pyodide.pyimport('foo')
let foo = pyodide.pyimport('foo');
```

*Parameters*
Expand Down
8 changes: 4 additions & 4 deletions docs/type_conversions.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ access arrays on the Javascript heap), and the data type is preserved. This
makes it easy to correctly convert it to a Numpy array using `numpy.asarray`:

```javascript
array = Float32Array([1, 2, 3])
let array = Float32Array([1, 2, 3]);
```

```python
Expand Down Expand Up @@ -112,7 +112,7 @@ Therefore, custom Python objects must be manually destroyed when passed to Javas
they will leak. To do this, call `.destroy()` on the object, after which Javascript will no longer have access to the object.

```javascript
var foo = pyodide.pyimport('foo');
let foo = pyodide.pyimport('foo');
foo.call_method();
foo.destroy();
foo.call_method(); // This will raise an exception, since the object has been
Expand All @@ -127,7 +127,7 @@ giving the name of the variable, and returns the object, converted to
Javascript.

```javascript
var sys = pyodide.pyimport('sys');
let sys = pyodide.pyimport('sys');
```
(type_conversions_using_js_obj_from_py)=
## Using Javascript objects from Python
Expand All @@ -152,7 +152,7 @@ Python, you may want to store it in a Python variable or use the `from js import
For example, given this large Javascript variable:

```javascript
var x = new Array(1000).fill(0)
let x = new Array(1000).fill(0);
```

Use it from Python as follows:
Expand Down
2 changes: 1 addition & 1 deletion docs/using_pyodide_from_webworker.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async function loadPythonPackages(){
pythonLoading = self.pyodide.loadPackage(['numpy', 'pytz']);
}

var onmessage = async(event) => {
let onmessage = async(event) => {
await languagePluginLoader;
// since loading package is asynchronous, we need to make sure loading is done:
await pythonLoading;
Expand Down
6 changes: 3 additions & 3 deletions src/pyodide.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* The main bootstrap script for loading pyodide.
*/

var languagePluginLoader = new Promise((resolve, reject) => {
globalThis.languagePluginLoader = new Promise((resolve, reject) => {
// Note: PYODIDE_BASE_URL is an environement variable replaced in
// in this template in the Makefile. It's recommended to always set
// languagePluginUrl in any case.
var baseURL = self.languagePluginUrl || '{{ PYODIDE_BASE_URL }}';
let baseURL = self.languagePluginUrl || '{{ PYODIDE_BASE_URL }}';
baseURL = baseURL.substr(0, baseURL.lastIndexOf('/')) + '/';

////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -316,7 +316,7 @@ var languagePluginLoader = new Promise((resolve, reject) => {
];

function makePublicAPI(module, public_api) {
var namespace = {_module : module};
let namespace = {_module : module};
for (let name of public_api) {
namespace[name] = module[name];
}
Expand Down
32 changes: 16 additions & 16 deletions src/templates/console.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
handleResult(c.push(line))
}

var term = $('body').terminal(
let term = $('body').terminal(
pushCode,
{
greetings: "Welcome to the Pyodide terminal emulator 🐍",
Expand All @@ -40,20 +40,20 @@
_c = Console(locals=globals())
`)

var c = pyodide.pyimport('_c')
let c = pyodide.pyimport('_c');

function handleResult(result) {
if (result) {
term.set_prompt('[[;gray;]... ]')
term.set_prompt('[[;gray;]... ]');
} else {
term.set_prompt('[[;red;]>>> ]')
var stderr = pyodide.runPython("sys.stderr.getvalue()").trim()
term.set_prompt('[[;red;]>>> ]');
let stderr = pyodide.runPython("sys.stderr.getvalue()").trim();
if (stderr) {
term.echo(`[[;red;]${stderr}]`)
term.echo(`[[;red;]${stderr}]`);
} else {
var stdout = pyodide.runPython("sys.stdout.getvalue()")
let stdout = pyodide.runPython("sys.stdout.getvalue()");
if (stdout) {
term.echo(stdout.trim())
term.echo(stdout.trim());
}
}
}
Expand All @@ -62,22 +62,22 @@
term.runPython = function(code) {
pyodide.runPythonAsync(code).then(
term.handlePythonResult, term.handlePythonError
)
}
);
};

term.handlePythonResult = function(result) {
if (result === undefined) {
return
return;
} else if (result['_repr_html_'] !== undefined) {
term.echo(result['_repr_html_'], {raw: true})
term.echo(result['_repr_html_'], {raw: true});
} else {
term.echo(result.toString())
term.echo(result.toString());
}
}
};

term.handlePythonError = function(result) {
term.error(result.toString())
}
term.error(result.toString());
};
});
</script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_jsproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def test_jsproxy_iter(selenium):
selenium.run_js(
"""
function makeIterator(array) {
var nextIndex = 0;
let nextIndex = 0;
return {
next: function() {
return nextIndex < array.length ?
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_load_package_after_convert_string(selenium):
See #93.
"""
selenium.run("import sys\n" "x = sys.version")
selenium.run_js("var x = pyodide.pyimport('x')\n" "console.log(x)")
selenium.run_js("let x = pyodide.pyimport('x');\n" "console.log(x);")
selenium.load_package("kiwisolver")
selenium.run("import kiwisolver")

Expand Down
14 changes: 7 additions & 7 deletions src/tests/test_typeconversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def test_typed_arrays(selenium, wasm_heap, jstype, pytype):
else:
selenium.run_js(
f"""
var buffer = pyodide._module._malloc(
let buffer = pyodide._module._malloc(
4 * {jstype}.BYTES_PER_ELEMENT);
window.array = new {jstype}(
pyodide._module.HEAPU8.buffer, buffer, 4);
Expand Down Expand Up @@ -210,7 +210,7 @@ def test_array_buffer(selenium):
def assert_js_to_py_to_js(selenium, name):
selenium.run_js(f"window.obj = {name};")
selenium.run("from js import obj")
assert selenium.run_js("return pyodide.globals['obj'] === obj")
assert selenium.run_js("return pyodide.globals['obj'] === obj;")


def assert_py_to_js_to_py(selenium, name):
Expand All @@ -230,7 +230,7 @@ def test_recursive_list_to_js(selenium_standalone):
x.append(x)
"""
)
selenium_standalone.run_js("x = pyodide.pyimport('x')")
selenium_standalone.run_js("x = pyodide.pyimport('x');")


def test_recursive_dict_to_js(selenium_standalone):
Expand All @@ -240,7 +240,7 @@ def test_recursive_dict_to_js(selenium_standalone):
x[0] = x
"""
)
selenium_standalone.run_js("x = pyodide.pyimport('x')")
selenium_standalone.run_js("x = pyodide.pyimport('x');")


def test_list_from_js(selenium):
Expand Down Expand Up @@ -272,7 +272,7 @@ class Point {
this.y = y;
}
}
window.point = new Point(42, 43)
window.point = new Point(42, 43);
"""
)
selenium.run(
Expand Down Expand Up @@ -309,7 +309,7 @@ def test_javascript_error(selenium):
def test_javascript_error_back_to_js(selenium):
selenium.run_js(
"""
window.err = new Error("This is a js error")
window.err = new Error("This is a js error");
"""
)
assert (
Expand All @@ -324,7 +324,7 @@ def test_javascript_error_back_to_js(selenium):
)
assert selenium.run_js(
"""
return pyodide.globals["py_err"] === err
return pyodide.globals["py_err"] === err;
"""
)

Expand Down

0 comments on commit 40bd093

Please sign in to comment.