mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-10-24 12:13:31 +08:00
feat: use ast-based helpers (#53125)
This commit is contained in:
@@ -28,7 +28,7 @@
|
||||
"@babel/plugin-transform-runtime": "7.23.7",
|
||||
"@babel/preset-env": "7.23.7",
|
||||
"@babel/preset-typescript": "7.23.3",
|
||||
"@freecodecamp/curriculum-helpers": "1.3.0",
|
||||
"@freecodecamp/curriculum-helpers": "2.3.0",
|
||||
"@types/chai": "4.3.12",
|
||||
"@types/copy-webpack-plugin": "^8.0.1",
|
||||
"@types/enzyme": "3.10.16",
|
||||
|
||||
@@ -46,6 +46,15 @@ async function setupPyodide() {
|
||||
// pyodide modifies self while loading.
|
||||
Object.freeze(self);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
||||
pyodide.FS.writeFile(
|
||||
'/home/pyodide/ast_helpers.py',
|
||||
helpers.python.astHelpers,
|
||||
{
|
||||
encoding: 'utf8'
|
||||
}
|
||||
);
|
||||
|
||||
ctx.postMessage({ type: 'contentLoaded' });
|
||||
|
||||
return pyodide;
|
||||
@@ -131,6 +140,20 @@ def __inputGen(xs):
|
||||
input = __inputGen(${JSON.stringify(input ?? [])})
|
||||
`);
|
||||
|
||||
runPython(`from ast_helpers import Node as _Node`);
|
||||
|
||||
// The tests need the user's code as a string, so we write it to the virtual
|
||||
// filesystem.
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
||||
pyodide.FS.writeFile('/user_code.py', code, { encoding: 'utf8' });
|
||||
|
||||
runPython(`
|
||||
with open("/user_code.py", "r") as f:
|
||||
from ast import parse as _parse
|
||||
_code = f.read()
|
||||
_tree = _parse(_code)
|
||||
`);
|
||||
|
||||
// Evaluates the learner's code so that any variables they define are
|
||||
// available to the test.
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user