{"id":17242910,"url":"https://github.com/imcuttle/babel-plugin-class-properties-default-value","last_synced_at":"2026-06-19T16:32:09.419Z","repository":{"id":45113082,"uuid":"120903447","full_name":"imcuttle/babel-plugin-class-properties-default-value","owner":"imcuttle","description":"babel-plugin-class-properties-default-value","archived":false,"fork":false,"pushed_at":"2022-01-07T14:25:40.000Z","size":26,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-25T14:09:37.481Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imcuttle.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"License","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-09T12:32:00.000Z","updated_at":"2018-02-09T12:32:16.000Z","dependencies_parsed_at":"2022-09-17T14:10:40.017Z","dependency_job_id":null,"html_url":"https://github.com/imcuttle/babel-plugin-class-properties-default-value","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/imcuttle/babel-plugin-class-properties-default-value","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcuttle%2Fbabel-plugin-class-properties-default-value","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcuttle%2Fbabel-plugin-class-properties-default-value/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcuttle%2Fbabel-plugin-class-properties-default-value/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcuttle%2Fbabel-plugin-class-properties-default-value/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imcuttle","download_url":"https://codeload.github.com/imcuttle/babel-plugin-class-properties-default-value/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcuttle%2Fbabel-plugin-class-properties-default-value/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34539706,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-19T02:00:06.005Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-15T06:14:22.880Z","updated_at":"2026-06-19T16:32:09.397Z","avatar_url":"https://github.com/imcuttle.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# babel-plugin-class-properties-default-value\n\nThe plugin for transform properties of class **which has parent class**.\n\n## Why need this\n\nWhen we use Babel to support [class properties](https://babeljs.io/docs/plugins/transform-class-properties/).\nLet's see the follow case: \n```javascript\nclass P {\n  value = 'value In P'\n  constructor(obj) {\n    Object.assign(this, obj)\n  }\n}\nclass S extends P {\n  val = 'value in S'\n}\n\nconsole.log(new S({ val: 'cus' }).val) // what should be printed? \n```\n\nI think the printed val should be 'cus' at first.\nBut actually, It's 'value in S'.\n\nthe above code will transform to the follow code by [transform class properties](https://babeljs.io/docs/plugins/transform-class-properties/).\n\n```javascript\nclass P {\n  constructor(obj) {\n    this.value = 'value In P'\n    Object.assign(this, obj)\n  }\n}\nclass S extends P {\n  constructor(...args) {\n    // After called super() that We can use this expression \n    super(...args)\n    this.val = 'value in S'\n  }\n}\nconsole.log(new S({ val: 'cus' }).val)\n```\n\n`super(...args)` meaning call the constructor of P and after called it `val === 'cus'`.\nUnfortunately, `this.val = 'value in S'` causes the shit happening.\nAnd this is ES6 inheritance's standard.\n\nSo if I want to regard `'value in S'` as DEFAULT VALUE by this way.\n\n```javascript\nclass S extends P {\n  constructor(...args) {\n    // After called super() that We can use this expression \n    super(...args)\n    this.val = this.hasOwnProperty('val') ? this.val : 'value in S'\n  }\n}\n```\n\n## Options\n\n- condType (default: 'typeofUndefined')  'typeofUndefined' | 'in' | 'hasOwnProperty'  \n  - 'typeofUndefined'  \n     this.val = typeof this.val !== 'undefined' ? this.val : 'value in S'\n  - 'in'  \n     this.val = 'val' in this ? this.val : 'value in S'\n  - 'hasOwnProperty'  \n     this.val = this.hasOwnProperty('val') ? this.val : 'value in S'\n    \n- effectThisExpr (default: false)  \n  Whether effecting the work on this expression  \n  `false` will ignore `this.val = this.abc`\n\n- onlyEffectConst (default: false)  \n  Whether effecting the constant only  \n  `true` will ignore options.effectThisExpr, only effect constant expressions\n\n- effectDecorator (default: false)  \n  Whether effecting the work on decorator  \n  `false` will ignore `@decorator this.val = 'val'`\n\n## Note\n\n```json5\n{\n  \"plugins\": [\n    // NOTE: the order is important\n    \"class-properties-default-value\",\n    \"transform-class-properties\"\n  ]\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimcuttle%2Fbabel-plugin-class-properties-default-value","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimcuttle%2Fbabel-plugin-class-properties-default-value","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimcuttle%2Fbabel-plugin-class-properties-default-value/lists"}