-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
2,843 additions
and
0 deletions.
There are no files selected for viewing
926 changes: 926 additions & 0 deletions
926
tests/codeblocks/javascript/ReactContextPropagation-test.js
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const asyncFunction = async () => { | ||
return new Promise((resolve, reject) => { | ||
setTimeout(() => { | ||
resolve('Async function resolved'); | ||
}, 1000); | ||
}); | ||
}; | ||
|
||
asyncFunction().then(console.log).catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
0 module `` | ||
1 function `const asyncFunction = async () =>` | ||
2 block_delimiter `{` | ||
2 statement `return` | ||
3 code `new Promise((resolve, reject) =>` | ||
4 block_delimiter `{` | ||
4 code `setTimeout(() =>` | ||
5 block_delimiter `{` | ||
5 code `resolve` | ||
6 code `('Async function resolved')` | ||
6 block_delimiter `;` | ||
5 block_delimiter `}` | ||
5 code `,` | ||
5 code `1000` | ||
5 block_delimiter `)` | ||
5 block_delimiter `;` | ||
4 block_delimiter `}` | ||
4 block_delimiter `)` | ||
3 block_delimiter `;` | ||
2 block_delimiter `}` | ||
2 block_delimiter `;` | ||
1 code `asyncFunction().then(console.log).catch` | ||
2 code `(console.error)` | ||
2 block_delimiter `;` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// 1. Variable Declarations | ||
let number = 10; | ||
const PI = 3.14; | ||
var oldSchoolVariable = 'This is old style'; | ||
|
||
// 2. Function Declaration | ||
function greet(name) { | ||
return `Hello, ${name}!`; | ||
} | ||
|
||
// 3. Arrow Function | ||
const square = (x) => x * x; | ||
|
||
// 4. Class Declaration | ||
class Person { | ||
constructor(name, age) { | ||
this.name = name; | ||
this.age = age; | ||
} | ||
|
||
introduce() { | ||
return `Hi, I'm ${this.name} and I'm ${this.age} years old.`; | ||
} | ||
} | ||
|
||
// 5. Object Literal | ||
const obj = { | ||
key: 'value', | ||
method() { | ||
return 'This is a method'; | ||
} | ||
}; | ||
|
||
// 6. Array Declaration | ||
const array = [1, 2, 3, 4]; | ||
|
||
// 7. Loops | ||
for (let i = 0; i < array.length; i++) { | ||
console.log(array[i]); | ||
} | ||
|
||
array.forEach((element) => { | ||
console.log(element); | ||
}); | ||
|
||
// 8. Conditional | ||
if (number > 5) { | ||
console.log('Number is greater than 5'); | ||
} else if (number === 5) { | ||
console.log('Number is 5 '); | ||
} else { | ||
console.log('Number is smaller than 5'); | ||
} | ||
|
||
if (number > 5) | ||
console.log('Number is greater than 5'); | ||
else | ||
console.log('Number is 5 or smaller'); | ||
|
||
// 9. Switch-case | ||
switch (number) { | ||
case 10: | ||
console.log('Number is 10'); | ||
break; | ||
default: | ||
console.log('Number is not 10'); | ||
break; | ||
} | ||
|
||
// 10. Try-catch | ||
try { | ||
throw new Error('This is an error'); | ||
} catch (error) { | ||
console.error('Caught an error:', error.message); | ||
} | ||
|
||
|
||
// 12. Destructuring | ||
const { key } = obj; | ||
const [firstElement] = array; | ||
|
||
// 13. Spread/Rest | ||
const newObj = { ...obj, newKey: 'newValue' }; | ||
const newArray = [...array, 5]; | ||
|
||
// 14. Template Literals | ||
const message = `This is a number: ${number}`; | ||
|
||
// 15. Import/Export (common in modules) | ||
export { greet }; | ||
import { greet } from './path-to-this-file'; | ||
|
||
console.log('Demonstration complete.'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
0 Module `` | ||
1 Comment `// 1. Variable Declarations (_1_Variable_Declaratio)` | ||
1 Assignment `let number = (number)` | ||
2 Code `10 (number.10)` | ||
2 Code `; (number._)` | ||
1 Assignment `const PI = (PI)` | ||
2 Code `3.14 (PI.3_14)` | ||
2 Code `; (PI._)` | ||
1 Code `var oldSchoolVariable = 'This is old style'; (var_oldSchoolVariable_)` | ||
1 Comment `// 2. Function Declaration (_2_Function_Declaratio)` | ||
1 Function `function greet(name) (greet)` | ||
2 Code `{ (greet._)` | ||
2 Statement `return (greet.return)` | ||
3 Code ``Hello, ${name}!` (greet.return._Hello_name_)` | ||
3 Code `; (greet.return._)` | ||
2 Code `} (greet.None_1)` | ||
1 Comment `// 3. Arrow Function (_3_Arrow_Function)` | ||
1 Function `const square = (x) => (square)` | ||
2 Code `x * x (square.x_x)` | ||
2 Code `; (square._)` | ||
1 Comment `// 4. Class Declaration (_4_Class_Declaration)` | ||
1 Class `class Person (Person)` | ||
2 Code `{ (Person._)` | ||
2 Constructor `constructor(name, age) (Person.constructor)` | ||
3 Code `{ (Person.constructor._)` | ||
3 Assignment `this.name = name; (Person.constructor.this_name_name_)` | ||
3 Assignment `this.age = age; (Person.constructor.this_age_age_)` | ||
3 Code `} (Person.constructor.None_1)` | ||
2 Function `introduce() (Person.introduce)` | ||
3 Code `{ (Person.introduce._)` | ||
3 Statement `return (Person.introduce.return)` | ||
4 Code ``Hi, I'm ${this.name} and I'm ${this.age} years old.` (Person.introduce.return._Hi_I_m_this_name_and)` | ||
4 Code `; (Person.introduce.return._)` | ||
3 Code `} (Person.introduce.None_1)` | ||
2 Code `} (Person.None_1)` | ||
1 Comment `// 5. Object Literal (_5_Object_Literal)` | ||
1 Assignment `const obj = (obj)` | ||
2 Code `{\n key: 'value',\n method() {\n return 'This is a method';\n }\n} (obj._)` | ||
2 Code `; (obj.None_1)` | ||
1 Comment `// 6. Array Declaration (_6_Array_Declaration)` | ||
1 Assignment `const array = (array)` | ||
2 Code `[1, 2, 3, 4] (array._1_2_3_4_)` | ||
2 Code `; (array._)` | ||
1 Comment `// 7. Loops (_7_Loops)` | ||
1 Statement `for (let i = 0; i < array.length; i++) (for_let_i_0_i_array)` | ||
2 Code `{\n console.log(array[i]);\n} (for_let_i_0_i_array._)` | ||
1 Call `array.forEach((element) => (array_forEach_element_)` | ||
2 Code `{ (array_forEach_element_._)` | ||
2 Call `console.log(element); (array_forEach_element_.console_log_element_)` | ||
2 Code `} (array_forEach_element_.None_1)` | ||
2 Code `) (array_forEach_element_.None_2)` | ||
1 Comment `// 8. Conditional (_8_Conditional)` | ||
1 Statement `if (number > 5) (if_number_5_)` | ||
2 Code `{\n console.log('Number is greater than 5');\n} (if_number_5_._)` | ||
2 Statement `else if (number === 5) (if_number_5_.else_if_number_5_)` | ||
3 Code `{\n console.log('Number is 5 ');\n} (if_number_5_.else_if_number_5_._)` | ||
3 Statement `else (if_number_5_.else_if_number_5_.else)` | ||
4 Code `{\n console.log('Number is smaller than 5');\n} (if_number_5_.else_if_number_5_.else._)` | ||
1 Statement `if (number > 5) (None_2)` | ||
2 Call `console.log (None_2.console_log)` | ||
3 Code `( (None_2.console_log._)` | ||
3 Code `'Number is greater than 5' (None_2.console_log._Number_is_greater_than_5)` | ||
3 Code `) (None_2.console_log.None_2)` | ||
2 Code `; (None_2._)` | ||
2 Statement `else (None_2.else)` | ||
3 Call `console.log (None_2.else.console_log)` | ||
4 Code `( (None_2.else.console_log._)` | ||
4 Code `'Number is 5 or smaller' (None_2.else.console_log._Number_is_5_or_smaller_)` | ||
4 Code `) (None_2.else.console_log.None_2)` | ||
3 Code `; (None_2.else._)` | ||
1 Comment `// 9. Switch-case (_9_Switch_case)` | ||
1 Statement `switch (number) (switch_number_)` | ||
2 Code `{ (switch_number_._)` | ||
2 Code `case 10:\n console.log('Number is 10');\n break; (switch_number_.case_10_)` | ||
2 Code `default:\n console.log('Number is not 10');\n break; (switch_number_.default_)` | ||
2 Code `} (switch_number_.None_3)` | ||
1 Comment `// 10. Try-catch (_10_Try_catch)` | ||
1 Code `try {\n throw new Error('This is an error');\n} catch (error) {\n console.error('Caught an error:', error.message);\n} (try_)` | ||
1 Comment `// 12. Destructuring (_12_Destructuring)` | ||
1 Assignment `const { key } = (key)` | ||
2 Code `obj (key.obj)` | ||
2 Code `; (key._)` | ||
1 Assignment `const [firstElement] = (const_firstElement_)` | ||
2 Code `array (const_firstElement_.array)` | ||
2 Code `; (const_firstElement_._)` | ||
1 Comment `// 13. Spread/Rest (_13_Spread_Rest)` | ||
1 Assignment `const newObj = (newObj)` | ||
2 Code `{ ...obj, newKey: 'newValue' } (newObj._obj_newKey_newVal)` | ||
2 Code `; (newObj._)` | ||
1 Assignment `const newArray = (newArray)` | ||
2 Code `[...array, 5] (newArray._array_5_)` | ||
2 Code `; (newArray._)` | ||
1 Comment `// 14. Template Literals (_14_Template_Literals)` | ||
1 Assignment `const message = (message)` | ||
2 Code ``This is a number: ${number}` (message._This_is_a_number_numb)` | ||
2 Code `; (message._)` | ||
1 Comment `// 15. Import/Export (common in modules) (_15_Import_Export_com)` | ||
1 Code `export { greet }; (export_greet_)` | ||
1 Import `import { greet } from './path-to-this-file'; (import_greet_from_)` | ||
1 Call `console.log (console_log)` | ||
2 Code `( (console_log._)` | ||
2 Code `'Demonstration complete.' (console_log._Demonstration_complete_)` | ||
2 Code `) (console_log.None_2)` | ||
1 Code `; (_)` |
Oops, something went wrong.