Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transformation error (Unexpected symbol <b> at ... #519

Open
jy95 opened this issue Aug 9, 2022 · 2 comments
Open

Transformation error (Unexpected symbol <b> at ... #519

jy95 opened this issue Aug 9, 2022 · 2 comments

Comments

@jy95
Copy link

jy95 commented Aug 9, 2022

Hello,

I am using JScodeshift to make some changes in json with my keycloak-capacitor project.

    // Replace dependancies
    return mainRoot
        .find(
            j.Property,
            {
                key: {
                    name: "dependancies"
                }
            }
        )
        .find(j.ObjectExpression)
        .replaceWith((nodePath) => {
            const { node } = nodePath;
            // replace properties
            node.properties = newProperties;
            return node;
        })
        .toSource({ quote: "double" });

However, it doesn't seem to work when toSource is invoked :

Transformation error (Unexpected symbol <b> at 37:28 35 |    }, 36 |    "dependencies":{ 37 |       "base64-js":"^1.5.1",base64-js"^1.5.1"
                      ^ 38 |       "js-sha256":"^0.9.0"js-sha256"^4.2.0" 39 |    },)
SyntaxError: Unexpected symbol <b> at 37:28
35 |    },
36 |    "dependencies":{
37 |       "base64-js":"^1.5.1",base64-js"^1.5.1"
                                ^
38 |       "js-sha256":"^0.9.0"js-sha256"^4.2.0"
39 |    },

If node.properties = newProperties; is put on comments, then I got no error but not the behavior I am expecting.

image

Steps to reproduce :

https://github.com/jy95/keycloak-capacitor/tree/jscodeshift-packageJson
git checkout jscodeshift-packageJson
npm install
npx jscodeshift -t update-packageJson.ts __testfixtures__/update-packageJson.input.json -originalKeycloakPath __testfixtures__/update-packageJson.input2.json  -d -p

Kind regards,

@Daniel15
Copy link
Member

Daniel15 commented Aug 9, 2022

I've never tried JSCodeshift for JSON files... Which parser are you using? Please link to an ASTExplorer.net repro.

For JSON, wouldn't it be easier to just use JSON.parse and manipulate it that way?

@jy95
Copy link
Author

jy95 commented Aug 10, 2022

@Daniel15 I was using json-estree-ast, a litle wrapper around json-to-ast
If I was able to deal with .d.ts files, why not the JSON files ?

When using another parser wrapper I created (momoa-estree-ast using this time @humanwhocodes/momoa ), I saw that JSCodeShift is doing weird stuff : dependencies isn't replaced and is broken, explaining why the other parser also failed :

{
       "name":"keycloak-capacitor",
       "version":"19.0.1",
       "description":"Keycloak adapter for Ionicframework with Capacitor support.",
       "main":"dist/keycloak.js",
       "module":"dist/keycloak.mjs",
       "types":"dist/keycloak.d.ts",
       "files":[
          "dist"
       ],
       "scripts":{
          "build":"rollup --config --configPlugin typescript",
          "prepublishOnly":"npm run build",
          "test":"npx jest"
       },
       "repository":{
          "type":"git",
          "url":"git+https://github.com/jy95/keycloak-capacitor.git"
       },
       "keywords":[
          "capacitor",
          "adapter",
          "auth",
          "authentication",
          "oauth2",
          "openid",
          "keycloak"
       ],
       "devDependencies":{
          "es6-promise":"^4.2.8",
          "jest":"^28.1.3",
          "jscodeshift":"^0.13.1",
          "tslib":"^2.4.0",
          "typescript":"^4.5.5"
       },
       "dependencies":{
          "base64-js":"^1.5.1","^1.5.1"
          "js-sha256":"^0.9.0""^4.2.0"
       },
       "author":"jy95",
       "license":"Apache-2.0",
       "bugs":{
          "url":"https://github.com/jy95/keycloak-capacitor/issues"
       },
       "homepage":"https://github.com/jy95/keycloak-capacitor#readme"
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants