@ilrksy/kelatescript 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const babel = require('@babel/core');
6
+ const kelantanPlugin = require('../plugin');
7
+
8
+ const filePath = process.argv[2];
9
+
10
+ if (!filePath) {
11
+ console.log('Sila masukkan fail: kelantanscript <fail.ks>');
12
+ process.exit(1);
13
+ }
14
+
15
+ const sourceCode = fs.readFileSync(path.resolve(filePath), 'utf-8');
16
+
17
+ // Transpile kod Kelantan ke JS
18
+ const { code } = babel.transformSync(sourceCode, {
19
+ plugins: [kelantanPlugin]
20
+ });
21
+
22
+ // Jalankan kod JavaScript yang dihasilkan
23
+ eval(code);
package/package.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "@ilrksy/kelatescript",
3
+ "version": "1.0.0",
4
+ "description": "Bahasa pengaturcaraan berasaskan dialek Kelantan",
5
+ "main": "index.js",
6
+ "bin": {
7
+ "kelatescript": "./bin/kelantanscript.js"
8
+ },
9
+ "dependencies": {
10
+ "@babel/core": "^7.0.0"
11
+ }
12
+ }
package/plugin.js ADDED
@@ -0,0 +1,31 @@
1
+ // Map kata kunci Kelantan ke JavaScript
2
+ const KATA_KUNCI = {
3
+ poyok: 'const',
4
+ buat: 'let',
5
+ royak: 'console.log',
6
+ sungguh: true,
7
+ doyok: false
8
+ };
9
+
10
+ module.exports = function({ types: t }) {
11
+ return {
12
+ visitor: {
13
+ // Menukar pembolehubah & fungsi khas
14
+ Identifier(path) {
15
+ if (path.node.name === 'royak') {
16
+ path.replaceWith(
17
+ t.memberExpression(t.identifier('console'), t.identifier('log'))
18
+ );
19
+ }
20
+ },
21
+ // Menukar poyok / buat kepada const / let
22
+ VariableDeclaration(path) {
23
+ if (path.node.kind === 'poyok') {
24
+ path.node.kind = 'const';
25
+ } else if (path.node.kind === 'buat') {
26
+ path.node.kind = 'let';
27
+ }
28
+ }
29
+ }
30
+ };
31
+ };