Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
react-vanilla
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Кубота
react-vanilla
Commits
d777739f
Commit
d777739f
authored
Apr 12, 2026
by
Иван Кубота
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
empty cls
parent
f06190a2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
405 additions
and
0 deletions
+405
-0
DOM.js
DOM.js
+3
-0
jsx.js
jsx.js
+402
-0
No files found.
DOM.js
View file @
d777739f
...
@@ -538,6 +538,9 @@ NS.apply = function(a,b) {
...
@@ -538,6 +538,9 @@ NS.apply = function(a,b) {
for
(;
i
<
_i
;
i
++
){
for
(;
i
<
_i
;
i
++
){
token
=
args
[
i
];
token
=
args
[
i
];
if
(
token
===
null
||
token
===
void
0
||
token
===
''
)
continue
;
if
(
typeof
token
===
'string'
&&
token
){
if
(
typeof
token
===
'string'
&&
token
){
out
.
push
(
token
);
out
.
push
(
token
);
}
else
if
(
typeof
token
===
'object'
){
}
else
if
(
typeof
token
===
'object'
){
...
...
jsx.js
0 → 100644
View file @
d777739f
/*
* A tiny JSX compiler
* Author: Matthew Levenstein
* License: MIT
*/
;(
function
(){
function
is_space
(
c
)
{
return
c
===
' '
||
c
===
'
\
t'
||
c
===
'
\
n'
}
function
is_numeric
(
c
)
{
c
=
c
.
charCodeAt
(
0
)
return
c
>=
48
&&
c
<=
57
}
function
is_alpha
(
c
)
{
c
=
c
.
charCodeAt
(
0
)
return
(
c
>=
65
&&
c
<=
90
)
||
(
c
>=
97
&&
c
<=
122
)
}
function
is_special
(
c
)
{
return
c
===
'-'
||
c
===
'_'
||
c
===
'$'
}
function
is_id_char
(
c
)
{
return
is_alpha
(
c
)
||
is_numeric
(
c
)
||
is_special
(
c
)
}
function
is_string
(
c
)
{
return
c
===
'"'
||
c
===
'
\'
'
||
c
===
'`'
}
function
is_sym
(
c
)
{
return
[
'<'
,
'>'
,
'='
,
'{'
,
'}'
,
')'
,
'.'
,
'('
].
indexOf
(
c
)
!==
-
1
}
function
compiler
(
js
,
replacement
)
{
var
tok
=
undefined
var
i
=
0
var
eof
=
js
.
length
var
tokens
=
[]
var
skip
=
0
var
lineno
=
1
var
dat
=
undefined
var
out
=
''
var
current
=
0
var
error
=
false
var
tag_buf
=
''
var
in_tag
=
false
while
(
i
<
eof
)
{
if
(
is_sym
(
js
[
i
]))
{
tok
=
{
type
:
js
[
i
],
data
:
js
[
i
++
]
}
}
else
if
(
is_string
(
js
[
i
]))
{
var
del
=
js
[
i
++
]
dat
=
''
while
(
i
<
eof
)
{
if
(
js
[
i
]
===
del
&&
js
[
i
-
1
]
!==
'
\
\'
)
break
if (js[i] === '
\
n
') skip++
dat += js[i++]
}
i++
tok = { type: '
string
', data: del + dat + del }
} else if (js[i] === '
/
') {
var n = js[++i]
dat = ''
if (n === '
/
') {
i++
while (i < eof) {
if (js[i] === '
\
n
') {
skip++
break
}
dat += js[i++]
}
tok = { type: '
comment
', data: dat }
} else if (n === '
*
') {
i++
while (i < eof) {
if (js[i] === '
*
' && js[i+1] === '
/
') {
i += 2
break
}
if (js[i] === '
\
n
') skip++
dat += js[i++]
}
tok = { type: '
comment
', data: dat }
} else {
tok = { type: '
/
', data: '
/
' }
}
} else {
if (is_alpha(js[i]) || is_special(js[i])) {
dat = ''
while (i < eof) {
if (!is_id_char(js[i]))
break
dat += js[i++]
}
tok = { type: '
name
', data: dat }
} else if (is_space(js[i])) {
dat = ''
while (i < eof) {
if (!is_space(js[i]))
break
if (js[i] === '
\
n
') skip++
dat += js[i++]
}
tok = { type: '
space
', data: dat }
} else {
dat = ''
while (i < eof) {
if (is_space(js[i]) || is_sym(js[i]) || is_string(js[i]))
break
dat += js[i++]
}
tok = { type: '
code
', data: dat }
}
}
tokens.push({
token: tok,
line: lineno
})
lineno += skip
skip = 0
}
function log (color, text) {
const colors = {
dim: '
\
x1b
[
2
m
',
bgred: '
\
x1b
[
41
m
',
red: '
\
x1b
[
31
m
',
default: '
\
x1b
[
0
m
'
}
console.log(colors[color], '
\
b
' + text, colors.default)
}
function printLine (l, caret, message) {
var char = ''
var start = l + '
|
'
var line = ''
var i
var nl
var c = 0
for (i = 0; i < tokens.length; i++) {
if (i === caret) c = line.length
if (tokens[i].line >= l) {
if (i > 0) {
nl = tokens[i-1].token.data.lastIndexOf('
\
n
')
if (tokens[i-1].line < l && nl !== -1) {
line += (tokens[i-1].token.data.slice(nl + 1))
}
}
if (tokens[i].line === l) {
if (tokens[i].token.type !== '
space
') {
line += tokens[i].token.data
} else {
if (i < tokens.length - 1 && tokens[i+1].line === l)
line += tokens[i].token.data
}
}
}
}
for (i = 0; i < start.length + c; i++) {
char += '
'
}
log('
bgred
', message)
log('
dim
', start + line)
log('
red
', char + '
^
')
}
function get_previous () {
var prev
if (tokens[current - 1].token.type === '
space
') prev = current - 2
else prev = current - 1
return prev
}
function emit (code) {
out += code
}
function next_token () {
if (!in_tag || tokens[current].token.type === '
space
') {
out += tokens[current].token.data
}
current++
}
function next () {
if (current < tokens.length - 1) next_token()
if (current < tokens.length - 1 && tokens[current].token.type === '
space
')
next_token()
}
function next_raw () {
if (current < tokens.length - 1) next_token()
}
function peek (type, num) {
if (tokens[current + (num || 0)].token.type === type) {
return true
}
return false
}
function accept (type) {
if (error) return
if (tokens[current].token.type === type) {
next()
return true
}
return false
}
function expect (type) {
if (error) return
var t = tokens[current]
if (t.token.type === type) {
next()
} else {
error = true
printLine(t.line, current, '
Error
:
unexpected
' + t.token.data)
}
}
function is_tag () {
var p = undefined
var possible = true
if (current === 0) {
possible = false
} else {
p = tokens[current - 1]
if (p.token.type === '
space
') {
if (current >= 2) p = tokens[current - 2]
else possible = false
}
}
if (peek('
<
')) {
if (
possible === true &&
(p.token.type !== '
name
' || p.token.data === '
return
') &&
p.token.type !== '
)
' &&
p.token.type !== '
}
'
) {
return true
}
}
return false
}
function parse_jsexpr () {
if (error) return
expect('
{
')
in_tag = false
emit('
(
')
parse_body(true)
emit('
)
')
in_tag = true
expect('
}
')
}
function parse_params (first) {
var key, val
if (error) return
if (accept('
name
')) {
if (!first) emit('
,
')
key = tokens[get_previous()].token.data
emit("'
" + key + "
'" + '
:
')
if (accept('
=
')) {
if (accept('
string
')) {
val = tokens[get_previous()].token.data
emit(val)
} else {
parse_jsexpr()
}
} else {
emit('
true
')
}
parse_params(false)
}
}
function parse_inner () {
var val
if (error) return
if (accept('
string
')) {
emit('
,
')
val = tokens[get_previous()].token.data
} else if (peek('
{
')) {
emit('
,
')
parse_jsexpr()
} else if (peek('
<
')) {
if (peek('
/
', 1)) {
return
} else {
emit('
,
')
parse_tag()
}
} else {
// @todo: escape strings and replace html chars with unicode chars ( , ©, etc)
var inner = ''
if (current > 0 && tokens[current - 1].token.type === '
space
') {
current--
}
while (!peek('
{
') && !peek('
string
') && !peek('
<
')) {
inner += tokens[current].token.data
next_raw()
}
emit('
,
')
emit('
"' + inner + '"
')
}
parse_inner()
}
function parse_closing (name) {
if (error) return
if (accept('
/
')) {
expect('
>
')
} else {
expect('
>
')
parse_inner()
expect('
<
')
expect('
/
')
expect('
name
')
var closing = get_previous()
if (tokens[closing].token.data !== name) {
printLine(tokens[closing].line, closing, '
Error
:
expected
closing
tag
for
' + name)
error = true
} else {
emit('
)
')
}
expect('
>
')
}
}
function parse_tag () {
var name, formatted
if (error) return
expect('
<
')
expect('
name
')
formatted = name = tokens[get_previous()].token.data
if (name[0].toUpperCase() !== name[0]) {
formatted = '
"' + name + '"
'
}
emit(replacement + '
(
' + formatted + '
,
')
emit('
{
')
parse_params(true)
emit('
}
')
parse_closing(name)
}
function parse_body (jsexpr) {
if (error) return
var c = -1
while (current < tokens.length - 1) {
if (error) return
if (jsexpr) {
if (peek('
{
')) c--
if (peek('
}
')) c++
if (c === 0) return
}
if (is_tag()) {
in_tag = true
parse_tag()
in_tag = false
} else {
next()
}
}
}
parse_body()
if (error) return js
else return out
}
if(typeof window !== undefined){
if(window.D) {
window.D && (window.D.jsx = compiler);
}
}else{
if(typeof module !== undefined){
}
}
})();
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment