jpsx 0.1.16 → 0.1.19
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.
- package/README.md +143 -242
- package/dist/api/__tests__/compile.test.js +2 -2
- package/dist/api/__tests__/runtime.test.js +129 -123
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +3 -0
- package/dist/generator/generator.js +2 -2
- package/dist/lexer/tokenizer.d.ts +4 -2
- package/dist/lexer/tokenizer.d.ts.map +1 -1
- package/dist/lexer/tokenizer.js +71 -29
- package/dist/parser/grammar.d.ts.map +1 -1
- package/dist/parser/grammar.js +148 -74
- package/dist/parser/parser.js +1 -1
- package/package.json +85 -53
package/README.md
CHANGED
|
@@ -1,242 +1,143 @@
|
|
|
1
|
-
# JPS (Just Python Script)
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
[ directory for complete working examples:
|
|
164
|
-
|
|
165
|
-
- **React** - Vite plugin, Webpack loader, runtime compilation
|
|
166
|
-
- **Vue 3** - Composition API integration
|
|
167
|
-
- **Svelte** - Component integration
|
|
168
|
-
- **Angular** - Service integration
|
|
169
|
-
- **Next.js** - App Router and Pages Router
|
|
170
|
-
- **Vanilla Browser** - No build step required
|
|
171
|
-
|
|
172
|
-
## 🛠️ Build Tool Plugins
|
|
173
|
-
|
|
174
|
-
### Vite
|
|
175
|
-
|
|
176
|
-
```javascript
|
|
177
|
-
// vite.config.js
|
|
178
|
-
import { jpsPlugin } from './vite-plugin-jps';
|
|
179
|
-
|
|
180
|
-
export default {
|
|
181
|
-
plugins: [jpsPlugin()]
|
|
182
|
-
};
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
### Webpack
|
|
186
|
-
|
|
187
|
-
```javascript
|
|
188
|
-
// webpack.config.js
|
|
189
|
-
module.exports = {
|
|
190
|
-
module: {
|
|
191
|
-
rules: [
|
|
192
|
-
{ test: /\.jps$/, use: 'jps-loader' }
|
|
193
|
-
]
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
See [INTEGRATION.md](docs/INTEGRATION.md) for Rollup, esbuild, and more.
|
|
199
|
-
|
|
200
|
-
## 🌟 Why JPS?
|
|
201
|
-
|
|
202
|
-
1. **Framework Agnostic**: Works with React, Vue, Svelte, Angular, and vanilla JS
|
|
203
|
-
2. **Flexible Output**: Choose the format that fits your needs
|
|
204
|
-
3. **Modern & Production-Ready**: Built with TypeScript, full test coverage
|
|
205
|
-
4. **Developer Friendly**: Simple API, great error messages, comprehensive docs
|
|
206
|
-
5. **Lightweight**: Minimal dependencies, tree-shakeable
|
|
207
|
-
|
|
208
|
-
## 🏗️ Development
|
|
209
|
-
|
|
210
|
-
Prerequisites: Node.js 18+
|
|
211
|
-
|
|
212
|
-
```bash
|
|
213
|
-
# Clone the repository
|
|
214
|
-
git clone https://github.com/your-repo/jps.git
|
|
215
|
-
cd jps
|
|
216
|
-
|
|
217
|
-
# Install dependencies
|
|
218
|
-
npm install
|
|
219
|
-
|
|
220
|
-
# Build the project
|
|
221
|
-
npm run build
|
|
222
|
-
|
|
223
|
-
# Run tests
|
|
224
|
-
npm test
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
## 📄 License
|
|
228
|
-
|
|
229
|
-
ISC - See [LICENSE](LICENSE) file for details
|
|
230
|
-
|
|
231
|
-
## 🤝 Contributing
|
|
232
|
-
|
|
233
|
-
Contributions are welcome! Please read our contributing guidelines first.
|
|
234
|
-
|
|
235
|
-
## 📮 Support
|
|
236
|
-
|
|
237
|
-
- **Issues**: [GitHub Issues](https://github.com/your-repo/jps/issues)
|
|
238
|
-
- **Discussions**: [GitHub Discussions](https://github.com/your-repo/jps/discussions)
|
|
239
|
-
|
|
240
|
-
---
|
|
241
|
-
|
|
242
|
-
**Made with ❤️ by Loaii abdalslam**
|
|
1
|
+
# JPS (Just Python Script)
|
|
2
|
+

|
|
3
|
+
|
|
4
|
+
A Python-like language that compiles to JavaScript, designed to integrate seamlessly with **any frontend framework**.
|
|
5
|
+
|
|
6
|
+
[](https://www.npmjs.com/package/jpsx)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
<a href="https://www.producthunt.com/products/jps?embed=true&utm_source=badge-featured&utm_medium=badge&utm_campaign=badge-jps" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=1067365&theme=light" alt="JPS - New Programming Language | Write Python-like in Javascript | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 🚀 Quick Start
|
|
13
|
+
|
|
14
|
+
### Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# Install as a library in your project
|
|
18
|
+
npm install jpsx
|
|
19
|
+
|
|
20
|
+
# Or install globally as a CLI tool
|
|
21
|
+
npm install -g jpsx
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### ⚡ Standalone File Integration (Recommended)
|
|
25
|
+
|
|
26
|
+
Import `.jps` files directly in your code - just like `.tsx` files!
|
|
27
|
+
|
|
28
|
+
**math.jps**
|
|
29
|
+
```python
|
|
30
|
+
def add(a, b):
|
|
31
|
+
return a + b
|
|
32
|
+
|
|
33
|
+
class Calculator:
|
|
34
|
+
def __init__(self):
|
|
35
|
+
self.value = 0
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**App.tsx**
|
|
39
|
+
```typescript
|
|
40
|
+
import { add, Calculator } from './math.jps';
|
|
41
|
+
|
|
42
|
+
const sum = add(10, 20);
|
|
43
|
+
const calc = new Calculator();
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## ✨ Features
|
|
49
|
+
|
|
50
|
+
- 🐍 **Python-like syntax** that compiles to clean JavaScript
|
|
51
|
+
- ⚡ **Standalone file integration** - Import `.jps` files like `.jsx/.tsx` files!
|
|
52
|
+
- 🔥 **Hot Module Replacement (HMR)** - Instant feedback during development
|
|
53
|
+
- ⚡ **Zero-config integration** with React, Vue, Svelte, Angular, and more
|
|
54
|
+
- 📦 **Multiple output formats**: ESM, CommonJS, IIFE, UMD
|
|
55
|
+
- 🔌 **Flexible runtime modes**: Inline, external, CDN, or custom
|
|
56
|
+
- 🛠️ **Build tool plugins** for Vite, Webpack, Rollup, esbuild
|
|
57
|
+
- 🌐 **Browser-ready**: Works without any build step
|
|
58
|
+
- 📝 **TypeScript support** with auto-generated declarations
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## 📖 Documentation & Guidelines
|
|
63
|
+
|
|
64
|
+
### 1. Language Syntax
|
|
65
|
+
JPS supports core Python syntax tailored for the JavaScript ecosystem.
|
|
66
|
+
|
|
67
|
+
| Feature | JPS Syntax | Compiles to JS |
|
|
68
|
+
|---------|------------|----------------|
|
|
69
|
+
| **Function** | `def foo(a): return a` | `function foo(a) { return a; }` |
|
|
70
|
+
| **Class** | `class User: ...` | `class User { ... }` |
|
|
71
|
+
| **Loop** | `for i in range(5): ...` | `for (let i = 0; i < 5; i++) ...` |
|
|
72
|
+
| **List Comp** | `[x*2 for x in nums]` | `nums.map(x => x * 2)` |
|
|
73
|
+
|
|
74
|
+
### 2. Runtime Functions
|
|
75
|
+
Built-in Python-like functions available globally:
|
|
76
|
+
- `print(args)`
|
|
77
|
+
- `len(obj)`
|
|
78
|
+
- `range(start, stop, step)`
|
|
79
|
+
- `sum(iterable)`
|
|
80
|
+
- `min() / max()`
|
|
81
|
+
- `sorted(iterable)`
|
|
82
|
+
|
|
83
|
+
### 3. CLI Usage
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# Initialize a new JPS project
|
|
87
|
+
jps init my-project
|
|
88
|
+
cd my-project
|
|
89
|
+
|
|
90
|
+
# Run a JPS file directly
|
|
91
|
+
jps run main.jps
|
|
92
|
+
|
|
93
|
+
# Build for production
|
|
94
|
+
jps build main.jps --format esm
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### 4. Integration Guide
|
|
98
|
+
|
|
99
|
+
**Vite Plugin**
|
|
100
|
+
```javascript
|
|
101
|
+
// vite.config.js
|
|
102
|
+
import { jpsPlugin } from 'vite-plugin-jpsx';
|
|
103
|
+
|
|
104
|
+
export default {
|
|
105
|
+
plugins: [jpsPlugin()]
|
|
106
|
+
};
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**Webpack Loader**
|
|
110
|
+
```javascript
|
|
111
|
+
// webpack.config.js
|
|
112
|
+
module.exports = {
|
|
113
|
+
module: {
|
|
114
|
+
rules: [
|
|
115
|
+
{ test: /\.jps$/, use: 'jpsx-loader' }
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## 🌟 Support Us
|
|
124
|
+
|
|
125
|
+
We are live on Product Hunt! If you like JPS, please support us:
|
|
126
|
+
|
|
127
|
+
<div style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; border: 1px solid rgb(224, 224, 224); border-radius: 12px; padding: 20px; max-width: 500px; background: rgb(255, 255, 255); box-shadow: rgba(0, 0, 0, 0.05) 0px 2px 8px;">
|
|
128
|
+
<div style="display: flex; align-items: center; gap: 12px; margin-bottom: 12px;">
|
|
129
|
+
<img alt="JPS" src="https://ph-files.imgix.net/99b42643-283d-47de-970f-27ae2be5a99a.jpeg?auto=format&fit=crop&w=80&h=80" style="width: 64px; height: 64px; border-radius: 8px; object-fit: cover; flex-shrink: 0;">
|
|
130
|
+
<div style="flex: 1 1 0%; min-width: 0px;">
|
|
131
|
+
<h3 style="margin: 0px; font-size: 18px; font-weight: 600; color: rgb(26, 26, 26); line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">JPS</h3>
|
|
132
|
+
<p style="margin: 4px 0px 0px; font-size: 14px; color: rgb(102, 102, 102); line-height: 1.4; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;">New Programming Language | Write Python-like in Javascript</p>
|
|
133
|
+
</div>
|
|
134
|
+
</div>
|
|
135
|
+
<a href="https://www.producthunt.com/products/jps?embed=true&utm_source=embed&utm_medium=post_embed" target="_blank" rel="noopener" style="display: inline-flex; align-items: center; gap: 4px; margin-top: 12px; padding: 8px 16px; background: rgb(255, 97, 84); color: rgb(255, 255, 255); text-decoration: none; border-radius: 8px; font-size: 14px; font-weight: 600;">Check it out on Product Hunt →</a>
|
|
136
|
+
</div>
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## 📄 License
|
|
141
|
+
ISC - See [LICENSE](LICENSE)
|
|
142
|
+
|
|
143
|
+
**Made with ❤️ by Loaii abdalslam**
|
|
@@ -75,11 +75,11 @@ describe("compile() - Runtime Modes", () => {
|
|
|
75
75
|
const source = 'print("test")';
|
|
76
76
|
test("should use external runtime by default", () => {
|
|
77
77
|
const result = compile(source);
|
|
78
|
-
expect(result.code).toContain("
|
|
78
|
+
expect(result.code).toContain("jps/runtime");
|
|
79
79
|
});
|
|
80
80
|
test("should use external runtime mode", () => {
|
|
81
81
|
const result = compile(source, { runtimeMode: "external" });
|
|
82
|
-
expect(result.code).toContain("
|
|
82
|
+
expect(result.code).toContain("jps/runtime");
|
|
83
83
|
});
|
|
84
84
|
test("should inline runtime code", () => {
|
|
85
85
|
const result = compile(source, { runtimeMode: "inline" });
|