{"id":16747591,"url":"https://github.com/differui/sfc-parser","last_synced_at":"2026-05-10T16:03:33.619Z","repository":{"id":81986107,"uuid":"129532576","full_name":"differui/sfc-parser","owner":"differui","description":"a toy vue sfc parser implementation","archived":false,"fork":false,"pushed_at":"2018-04-14T16:15:39.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-16T02:28:35.098Z","etag":null,"topics":["sfc","vue"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/differui.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2018-04-14T16:03:39.000Z","updated_at":"2019-09-12T02:51:36.000Z","dependencies_parsed_at":"2023-07-14T15:33:01.660Z","dependency_job_id":null,"html_url":"https://github.com/differui/sfc-parser","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/differui/sfc-parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/differui%2Fsfc-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/differui%2Fsfc-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/differui%2Fsfc-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/differui%2Fsfc-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/differui","download_url":"https://codeload.github.com/differui/sfc-parser/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/differui%2Fsfc-parser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273046347,"owners_count":25036175,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-31T02:00:09.071Z","response_time":79,"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":["sfc","vue"],"created_at":"2024-10-13T02:10:28.730Z","updated_at":"2026-05-10T16:03:33.318Z","avatar_url":"https://github.com/differui.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sfc-parser\n\u003e a tony vue sfc parser implementation\n\n## Install\n\n```bash\nnpm i sfc-parser\n```\n\n## Usage\n\n```javascript\nimport { tokenize, parse, compile } from 'sfc-parser';\n\nconst source = `\n\u003ctemplate\u003e\n  \u003cdiv class=\"app\"\u003e\n    \u003ch1\u003e{{ msg }}\u003c/h1\u003e\n  \u003c/div\u003e\n\u003c/template\u003e\n\n\u003cscript\u003e\nexport default {\n  data () {\n    return {\n      msg: 'hello'\n    }\n  }\n}\n\u003c/script\u003e\n\n\u003cstyle\u003e\n.app h1 {\n  color: red\n}\n\u003c/style\u003e\n`;\nconst tokens = tokenize(source);\nconst ast = parse(source);\n\ncompile(source, {\n  scan: false, // true =\u003e same as tokenize(source)\n  parse: false, // true =\u003e same as parse(source)\n});\n```\n\n## Grammar\n\nThis is non-official ebnf grammar of Vue single file component. Only keeps minimal descriptions for the tony sfc parser.For more information please visit vue sfc spec: https://vue-loader.vuejs.org/en/start/spec.html\n\n```ebnf\n# metacharacters\n*: 0 or more\n+: 1 or more\n?: 0 or 1\n|: separates alternatives\n[]: grouping\n\n# regular expression\nTAG_NAME: /(script|template|style)/\nLT: /\u003c/\nGT: /\u003e/\nSLASH: /\\//\nS: /\\s+/\nALPHABETS: /\\w/\nDIGITS: /\\d/\nQUOTE: /\"/\nEQ: /=/\nTEXT: /[^\u003c\u003e\\/\\s\\w\\d\"=]*/\n\n# rules\nsfc\n  : S* [ block? S* ]*\n  ;\nblock\n  : open S* content S* close\n  ;\nopen\n  : LT TAG_NAME S* [ attr? S* ]* GT\n  ;\nclose\n  : LT SLASH TAG_NAME S* GT\n  ;\ncontent\n  : [ TEXT | LT | GT | SLASH | S | ALPHABETS | DIGITS | QUOTE | EQ | TAG_NAME ]*\n  ;\nattr\n  : [ ALPHABETS | DIGITS ]+ S* [ EQ S* QUOTE ALPHABETS QUOTE ]?\n  ;\n```\n\n## License\n\nMIT \u0026copy; [BinRui Guan](mailto:differui@gmail.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdifferui%2Fsfc-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdifferui%2Fsfc-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdifferui%2Fsfc-parser/lists"}